solc-typed-ast icon indicating copy to clipboard operation
solc-typed-ast copied to clipboard

Typestring parser crashes on some cases of shadowing

Open cd1m0 opened this issue 3 years ago • 0 comments

Given the following code:

contract Test {
    struct Test {
        uint x;
    }

    function main() public {
         this;
    }
}

The type string of this is contract Test. When trying to parse that however the typestring parser will fail with the following exception:

     Error: Couldn't find ContractDefinition Test
      at makeUserDefinedType (src/types/typeStrings/typeString_parser.ts:153:15)
      at peg$c204 (src/types/typeStrings/typeString_parser.ts:636:18)
      at peg$parseUserDefinedType (src/types/typeStrings/typeString_parser.ts:4380:24)
      at peg$parseSimpleType (src/types/typeStrings/typeString_parser.ts:3685:30)
      at peg$parseNonArrPtrType (src/types/typeStrings/typeString_parser.ts:5367:12)
      at peg$parseArrayPtrType (src/types/typeStrings/typeString_parser.ts:5391:10)
      at peg$parseType (src/types/typeStrings/typeString_parser.ts:5655:20)
      at peg$parseStart (src/types/typeStrings/typeString_parser.ts:901:12)
      at peg$parse (src/types/typeStrings/typeString_parser.ts:5667:16)
      at getNodeType (src/types/typeStrings/typeString_parser.ts:109:17)
      at Context.<anonymous> (test/integration/types/typestrings.spec.ts:159:53)

This is due to the fact that in normal resolving logic the Test struct shadows the contract definition for Test.

Since we are planing on deprecating the typestring parser, moving it under test/ and only using it to test the correctness of InferType we might not fix this edge case, unless there's demand for it.

cd1m0 avatar Oct 12 '22 19:10 cd1m0