-
Notifications
You must be signed in to change notification settings - Fork 69
refactor(parser): move mapping key type validation to semantic analysis #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
e85c63a
127cb3d
e6c7faa
ff3dcb8
d8a061d
590dd9c
b12ca94
3eb63f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| type U is int; | ||
| enum E { | ||
| A, | ||
| B | ||
| } | ||
|
|
||
| library L{ | ||
| enum E1 { | ||
| A, | ||
| B | ||
| } | ||
| } | ||
|
|
||
| contract C { | ||
| mapping(uint => uint) m0; | ||
| mapping(E => uint) m1; | ||
| mapping(U => uint) m2; | ||
| mapping(L.E1 => uint) m3; | ||
| mapping(uint[] => uint) m4; //~ ERROR: expected `=>`, found `[` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the PR overall looks good to me, but I'm mulling over this, I understand that this is technically incorrect syntax but part of me wishes this was a more helpful message. no action needed right now as I'm still figuring out if we want it like this or not
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point. mapping(uint[] => uint) m4;but the following: mapping([] => uint) m4;would return a more insightful error message: |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| error: expected `=>`, found `[` | ||
| --> ROOT/tests/ui/parser/mapping_key_type.sol:LL:CC | ||
| | | ||
| LL | mapping(uint[] => uint) m4; | ||
| | ^ expected `=>` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //@compile-flags: -Ztypeck | ||
| type U is int; | ||
| enum E { | ||
| A, | ||
| B | ||
| } | ||
|
|
||
| library L{ | ||
| enum E1 { | ||
| A, | ||
| B | ||
| } | ||
| struct S1 { | ||
| int x; | ||
| } | ||
| } | ||
|
|
||
| contract C { | ||
| mapping(uint => uint) m0; | ||
| mapping(string => uint) m1; | ||
| mapping(E => uint) m2; | ||
| mapping(U => uint) m3; | ||
| mapping(L.E1 => uint) m4; | ||
| mapping(L.S1 => uint) m5; //~ ERROR: Only elementary types, user defined value types, contract types or enums are allowed as mapping keys. | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| error: Only elementary types, user defined value types, contract types or enums are allowed as mapping keys. | ||
| --> ROOT/tests/ui/typeck/mapping_key_type_check.sol:LL:CC | ||
| | | ||
| LL | mapping(L.S1 => uint) m5; | ||
| | ^^^^ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.