Emit warnings for keywords selected to be reserved in the future - #16206
Conversation
586c3ca to
268a776
Compare
268a776 to
fb8ef20
Compare
| "\"{}\" will be promoted to reserved keyword in the next breaking version" | ||
| " and will not be allowed as an identifier anymore.", |
There was a problem hiding this comment.
Not necessarily something to change here, but just wanted to note that our terminology is all over the place: "keyword" vs "reserved keyword" vs "reserved identifier". We should get that straight at some point, because these are not synonyms.
There was a problem hiding this comment.
True, I will try to align that and instead of "reserved keyword" use just "keyword" and not mix with "reserved identifiers".
There was a problem hiding this comment.
I'd add a few more tests:
- That the future keywords trigger the warning when used as:
- module name (
import ... as Xorimport * as X from ...) - alias name (
import {... as X} from ...) - UDVT name
- struct/enum field name
- Yul variable/function name
- module name (
- That the future Yul keywords (i.e.
leave) do trigger the warning outside of Yul.- It's actually up for discussion whether these should be reserved at Solidity level, but so far that has been the case with all other Yul keywords (including
switchandlet, which have no functionality in Solidity).
- It's actually up for discussion whether these should be reserved at Solidity level, but so far that has been the case with all other Yul keywords (including
- That the future Yul reserved identifiers (e.g.
blobhash) do not trigger the warning outside of Yul.
There was a problem hiding this comment.
I have added some tests and verified that others cover the suggestions you made. Only thing that is missing is the point about Yul variable/function name, because keywords don't seem to trigger any error when used as identifiers in inline assembly and pure Yul.
That the future keywords trigger the warning when used as:
-
module name (import ... as X or import * as X from ...)
- imports/import_name_future_keyword_warning.sol
-
alias name (import {... as X} from ...)
- imports/import_alias_name_future_keyword_warning.sol
-
UDVT name
- userDefinedValueType/udvt_name_future_keyword_warning.sol
-
struct/enum field name
- syntaxTests/enums/enum_name_future_keyword_warning.sol
- test/libsolidity/syntaxTests/structs/illegal_names.sol
- test/libsolidity/syntaxTests/structs/struct_name_future_keyword_warning.sol
-
Yul variable/function name (?)
-
Solidity Keywords (or reserved) do not trigger any error or warning in assembly or pure Yul. Not sure if that is what you were suggesting.
see yulSyntaxTests/solidity_keywords.yul and syntaxTests/inlineAssembly/solidity_keywords.sol
leaveis already a keyword in Yul.
That the future Yul keywords (i.e. leave) do trigger the warning outside of Yul.
- test/libsolidity/syntaxTests/variableDeclaration/variable_named_leave.sol
That the future Yul reserved identifiers (e.g. blobhash) do not trigger the warning outside of Yul.
- syntaxTests/globalFunctions/blobhash_function_pre_cancun.sol (already existent)
- syntaxTests/globalFunctions/blobhash_var_shadow_warning.sol (already existent)
- syntaxTests/globalFunctions/blobhash_function_shadow_warning.sol (already existent)
There was a problem hiding this comment.
Solidity Keywords (or reserved) do not trigger any error or warning in assembly or pure Yul. Not sure if that is what you were suggesting.
Interesting. I was not aware of that. No need to change it then. It's a bit weird, but if it's not a bug but the way things were designed then it's fine.
Still good to have that covered with tests though.
There was a problem hiding this comment.
They are covered. I checked and updated with some missing keywords.
test/libsolidity/syntaxTests/inlineAssembly/solidity_keywords.sol
fb8ef20 to
60a17c0
Compare
caf8f3f to
89d4c6a
Compare
2b08142 to
d223a50
Compare
c1eb335 to
2d30418
Compare
|
@cameel , this should be ready to be merged. |
|
Sure, will take a look soon. Would be good to get this one into the next release. |
cameel
left a comment
There was a problem hiding this comment.
This is good for the most part. I have some change suggestions but they're minor enough (we could do away with some redundant warnings) that I think we can still merge this for the release and do them in a follow-up PR. So if you don't manage to resolve my comments today, feel free to merge and do just that.
Just make sure to apply the changelog suggestions.
8105381 to
2fa25f4
Compare
5f601da to
8323b1b
Compare
ebdb163 to
7b49c7e
Compare
7b49c7e to
a0c3652
Compare
a0c3652 to
5f6fbd4
Compare
5f6fbd4 to
ad2fda2
Compare
Partially solves #15795 and #14770.