:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
When resolving relative imports with leading ../ segments the compiler stops at the root of its virtual filesystem and ignores any superfluous segments (see documentation for relative imports). For example import "../../../../d.sol" resolves into d.sol when found inside a/b/c.sol. Truffle instead follows the path outside of project directory resulting in such imports not working correctly. The way it works now it can result in the wrong file being imported which could go unnoticed by the user.
I think these imports should be reported as an error because this is just an obscure corner case that is not really worth supporting in practice. It's more likely to be a mistake on user's part and reporting it would be better. Even if Truffle used the correct path, they would not work anyway due to the recently added project:/ prefix (#4137).
Issue
When resolving relative imports with leading
../
segments the compiler stops at the root of its virtual filesystem and ignores any superfluous segments (see documentation for relative imports). For exampleimport "../../../../d.sol"
resolves intod.sol
when found insidea/b/c.sol
. Truffle instead follows the path outside of project directory resulting in such imports not working correctly. The way it works now it can result in the wrong file being imported which could go unnoticed by the user.I think these imports should be reported as an error because this is just an obscure corner case that is not really worth supporting in practice. It's more likely to be a mistake on user's part and reporting it would be better. Even if Truffle used the correct path, they would not work anyway due to the recently added
project:/
prefix (#4137).Steps to Reproduce
Actual Results
The
sources
dict in the JSON input contains these entries:Expected Behavior
Something like this works fine as an input to the compiler because it resolves
../../C.sol
intoC.sol
:For Truffle this is not viable due to the
project:/
prefix so I think this case should simply be disallowed.Environment
5.3.14
and currentdevelop
(abfb3646eea9d57e0a6f9186c12bb51680c181d8)v16.4.2
7.17.0