Waffle icon indicating copy to clipboard operation
Waffle copied to clipboard

Waffle tries to resolve commented imports

Open cavanmflynn opened this issue 4 years ago • 2 comments

The following will fail to compile with error: Error: None of the sub-resolvers resolved "./NonExistent.sol" location.

pragma solidity ^0.5.7;

// import "./NonExistent.sol";

cavanmflynn avatar Jul 16 '20 18:07 cavanmflynn

I just ran into this issue as well, stumped me for a few minutes

lastmjs avatar Aug 21 '20 03:08 lastmjs

The issue at hand is caused by the regex in the resolver project. I've written a regex that omits comments (both inline and multiline) and includes curly bracket notation in imports e.g import { A, B, C as D } from "./alphabet.sol";. However, it's hard for regex, in this case, to take into consideration escaped characters and on top of that, it's not entirely safe due to backreferencing/backtracing. It would be much better to use a solidity parser instead of a regex.

My regex: /^\s*import(?:\s+|(?:\s*(?:\/{2})+.*?\s+)*|(?:\s*\/\*.*?\*\/\s+)*)(?:(?:'([^\n\r]+)')|(?:"([^\n\r]+)")|(?:{\s*[^\n\r]+\s*})|(?:\*|\w+))(?:\s+as\s+\w+)?(?:\s+from\s+(?:(?:'([^\n\r]+)')|(?:"([^\n\r]+)")))?;/gms

duckception avatar Oct 06 '20 13:10 duckception