Description
From #10976 (comment)
Abstract
Currently the compiler ignores any number of slashes at the end of the name of an imported module. For example this test case is perfectly valid:
==== Source: a/b/c.sol ====
contract C {}
==== Source: a/b/d.sol ====
import "./c.sol/";
contract D is C {}
I think that this should result in a compilation error instead. Only import "./c.sol";
should be accepted.
Motivation
I see no legitimate need for these trailing slashes. I haven't seen this used in practice and if I did, I would probably be confused by it - Solidity does not currently allow importing whole directories but it looks like such an import.
It's also a source of bugs due to libraries not supporting all edge cases correctly (e.g. #10713). Disallowing this would free us from worrying about some of these edge cases.
Specification
If the path passed to import
ends with /
, the compiler should issue an error saying that it's not possible to import a directory. For consistency, the compiler might also issue this error if it determines that an import not ending with a slash is pointing at a directory.
Alternatively, given that user might not understand that the compiler sees a file with a trailing slash as a directory, the message could just say that imported paths cannot end with a slash.
Backwards Compatibility
This will break code that uses this style of import. Such code is easy to fix by removing the slash but it's still a breaking change.