Skip to content

Commit

Permalink
fix: Only allow an identifier in the Yul variable declaration position (
Browse files Browse the repository at this point in the history
#948)

Previously, Yul identifiers could have dots in the name but that's not
the case starting from 0.7. As such, we need to disallow these forms for
the variable declaration and instead only accept the identifier, as is
done by the upstream grammar.

Thanks @OmarTawfik for finding this!
  • Loading branch information
Xanewok committed Apr 25, 2024
1 parent 2e88b8f commit ce88cb7
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-shoes-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/slang": patch
---

Restrict the grammar to correctly only allow an identifier in Yul variable declaration
2 changes: 1 addition & 1 deletion crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4209,7 +4209,7 @@ codegen_language_macros::compile!(Language(
name = YulVariableDeclarationStatement,
fields = (
let_keyword = Required(YulLetKeyword),
names = Required(YulPaths),
names = Required(YulIdentifier),
value = Optional(reference = YulVariableDeclarationValue)
)
),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/solidity/outputs/spec/generated/grammar.ebnf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ Tree:
- (leading_trivia꞉ SingleLineComment): '// ColonEqual was two separate tokens before "0.5....' # (0..53)
- (leading_trivia꞉ EndOfLine): "\n" # (53..54)
- (let_keyword꞉ YulLetKeyword): "let" # (54..57)
- (names꞉ YulPaths): # " foo" (57..61)
- (item꞉ YulPath): # " foo" (57..61)
- (item꞉ YulPathComponent): # " foo" (57..61)
- (leading_trivia꞉ Whitespace): " " # (57..58)
- (variant꞉ YulIdentifier): "foo" # (58..61)
- (leading_trivia꞉ Whitespace): " " # (57..58)
- (names꞉ YulIdentifier): "foo" # (58..61)
- (value꞉ YulVariableDeclarationValue): # " : = 0\n" (61..68)
- (assignment꞉ YulAssignmentOperator) ► (variant꞉ YulColonAndEqual): # " : =" (61..65)
- (leading_trivia꞉ Whitespace): " " # (61..62)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ Tree:
- (leading_trivia꞉ SingleLineComment): '// ColonEqual was two separate tokens before "0.5....' # (0..53)
- (leading_trivia꞉ EndOfLine): "\n" # (53..54)
- (let_keyword꞉ YulLetKeyword): "let" # (54..57)
- (names꞉ YulPaths): # " foo" (57..61)
- (item꞉ YulPath): # " foo" (57..61)
- (item꞉ YulPathComponent): # " foo" (57..61)
- (leading_trivia꞉ Whitespace): " " # (57..58)
- (variant꞉ YulIdentifier): "foo" # (58..61)
- (leading_trivia꞉ Whitespace): " " # (57..58)
- (names꞉ YulIdentifier): "foo" # (58..61)
- (leading_trivia꞉ Whitespace): " " # (61..62)
- (SKIPPED): ": = 0\n" # (62..68)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ let a.b.c := 1 │ 0..14
Errors: # 1 total
- >
Error: Expected Colon or ColonEqual.
╭─[crates/solidity/testing/snapshots/cst_output/YulVariableDeclarationStatement/identifier_with_dots/input.sol:1:6]
1 │ let a.b.c := 1
│ ─────┬────
│ ╰────── Error occurred here.
───╯
Tree:
- (YulVariableDeclarationStatement): # "let a.b.c := 1\n" (0..15)
- (let_keyword꞉ YulLetKeyword): "let" # (0..3)
- (leading_trivia꞉ Whitespace): " " # (3..4)
- (names꞉ YulIdentifier): "a" # (4..5)
- (SKIPPED): ".b.c := 1\n" # (5..15)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ let a.b.c := 1 │ 0..14
Errors: # 1 total
- >
Error: Expected ColonEqual.
╭─[crates/solidity/testing/snapshots/cst_output/YulVariableDeclarationStatement/identifier_with_dots/input.sol:1:6]
1 │ let a.b.c := 1
│ ─────┬────
│ ╰────── Error occurred here.
───╯
Tree:
- (YulVariableDeclarationStatement): # "let a.b.c := 1\n" (0..15)
- (let_keyword꞉ YulLetKeyword): "let" # (0..3)
- (leading_trivia꞉ Whitespace): " " # (3..4)
- (names꞉ YulIdentifier): "a" # (4..5)
- (SKIPPED): ".b.c := 1\n" # (5..15)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ let a.b.c := 1 │ 0..14
Errors: []

Tree:
- (YulVariableDeclarationStatement): # "let a.b.c := 1\n" (0..15)
- (let_keyword꞉ YulLetKeyword): "let" # (0..3)
- (leading_trivia꞉ Whitespace): " " # (3..4)
- (names꞉ YulIdentifier): "a.b.c" # (4..9)
- (value꞉ YulVariableDeclarationValue): # " := 1\n" (9..15)
- (assignment꞉ YulAssignmentOperator): # " :=" (9..12)
- (leading_trivia꞉ Whitespace): " " # (9..10)
- (variant꞉ ColonEqual): ":=" # (10..12)
- (expression꞉ YulExpression) ► (variant꞉ YulLiteral): # " 1\n" (12..15)
- (leading_trivia꞉ Whitespace): " " # (12..13)
- (variant꞉ YulDecimalLiteral): "1" # (13..14)
- (trailing_trivia꞉ EndOfLine): "\n" # (14..15)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ let a.b.c := 1 │ 0..14
Errors: # 1 total
- >
Error: Expected ColonEqual.
╭─[crates/solidity/testing/snapshots/cst_output/YulVariableDeclarationStatement/identifier_with_dots/input.sol:1:6]
1 │ let a.b.c := 1
│ ─────┬────
│ ╰────── Error occurred here.
───╯
Tree:
- (YulVariableDeclarationStatement): # "let a.b.c := 1\n" (0..15)
- (let_keyword꞉ YulLetKeyword): "let" # (0..3)
- (leading_trivia꞉ Whitespace): " " # (3..4)
- (names꞉ YulIdentifier): "a" # (4..5)
- (SKIPPED): ".b.c := 1\n" # (5..15)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let a.b.c := 1
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Tree:
- (leading_trivia꞉ SingleLineComment): "// Unreserved in Yul specifically since 0.7.1:" # (0..46)
- (leading_trivia꞉ EndOfLine): "\n" # (46..47)
- (let_keyword꞉ YulLetKeyword): "let" # (47..50)
- (names꞉ YulPaths): # " bytes\n" (50..57)
- (item꞉ YulPath): # " bytes\n" (50..57)
- (item꞉ YulPathComponent): # " bytes\n" (50..57)
- (leading_trivia꞉ Whitespace): " " # (50..51)
- (variant꞉ YulIdentifier): "bytes" # (51..56)
- (trailing_trivia꞉ EndOfLine): "\n" # (56..57)
- (leading_trivia꞉ Whitespace): " " # (50..51)
- (names꞉ YulIdentifier): "bytes" # (51..56)
- (trailing_trivia꞉ EndOfLine): "\n" # (56..57)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Tree:
- (leading_trivia꞉ SingleLineComment): "// Unreserved in Yul specifically since 0.7.1:" # (0..46)
- (leading_trivia꞉ EndOfLine): "\n" # (46..47)
- (let_keyword꞉ YulLetKeyword): "let" # (47..50)
- (names꞉ YulPaths): # " bytes1\n" (50..58)
- (item꞉ YulPath): # " bytes1\n" (50..58)
- (item꞉ YulPathComponent): # " bytes1\n" (50..58)
- (leading_trivia꞉ Whitespace): " " # (50..51)
- (variant꞉ YulIdentifier): "bytes1" # (51..57)
- (trailing_trivia꞉ EndOfLine): "\n" # (57..58)
- (leading_trivia꞉ Whitespace): " " # (50..51)
- (names꞉ YulIdentifier): "bytes1" # (51..57)
- (trailing_trivia꞉ EndOfLine): "\n" # (57..58)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Tree:
- (leading_trivia꞉ SingleLineComment): "// Unreserved in Yul specifically since 0.7.1:" # (0..46)
- (leading_trivia꞉ EndOfLine): "\n" # (46..47)
- (let_keyword꞉ YulLetKeyword): "let" # (47..50)
- (names꞉ YulPaths): # " bytes11\n" (50..59)
- (item꞉ YulPath): # " bytes11\n" (50..59)
- (item꞉ YulPathComponent): # " bytes11\n" (50..59)
- (leading_trivia꞉ Whitespace): " " # (50..51)
- (variant꞉ YulIdentifier): "bytes11" # (51..58)
- (trailing_trivia꞉ EndOfLine): "\n" # (58..59)
- (leading_trivia꞉ Whitespace): " " # (50..51)
- (names꞉ YulIdentifier): "bytes11" # (51..58)
- (trailing_trivia꞉ EndOfLine): "\n" # (58..59)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Tree:
- (leading_trivia꞉ SingleLineComment): "// This form is reserved only since 0.4.14 until 0..." # (0..62)
- (leading_trivia꞉ EndOfLine): "\n" # (62..63)
- (let_keyword꞉ YulLetKeyword): "let" # (63..66)
- (names꞉ YulPaths): # " ufixed184x80\n" (66..80)
- (item꞉ YulPath): # " ufixed184x80\n" (66..80)
- (item꞉ YulPathComponent): # " ufixed184x80\n" (66..80)
- (leading_trivia꞉ Whitespace): " " # (66..67)
- (variant꞉ YulIdentifier): "ufixed184x80" # (67..79)
- (trailing_trivia꞉ EndOfLine): "\n" # (79..80)
- (leading_trivia꞉ Whitespace): " " # (66..67)
- (names꞉ YulIdentifier): "ufixed184x80" # (67..79)
- (trailing_trivia꞉ EndOfLine): "\n" # (79..80)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Tree:
- (leading_trivia꞉ SingleLineComment): "// This form is reserved only since 0.4.14 until 0..." # (0..62)
- (leading_trivia꞉ EndOfLine): "\n" # (62..63)
- (let_keyword꞉ YulLetKeyword): "let" # (63..66)
- (names꞉ YulPaths): # " ufixed184x80\n" (66..80)
- (item꞉ YulPath): # " ufixed184x80\n" (66..80)
- (item꞉ YulPathComponent): # " ufixed184x80\n" (66..80)
- (leading_trivia꞉ Whitespace): " " # (66..67)
- (variant꞉ YulIdentifier): "ufixed184x80" # (67..79)
- (trailing_trivia꞉ EndOfLine): "\n" # (79..80)
- (leading_trivia꞉ Whitespace): " " # (66..67)
- (names꞉ YulIdentifier): "ufixed184x80" # (67..79)
- (trailing_trivia꞉ EndOfLine): "\n" # (79..80)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Tree:
- (leading_trivia꞉ SingleLineComment): "// This form is reserved only since 0.4.14 until 0..." # (0..62)
- (leading_trivia꞉ EndOfLine): "\n" # (62..63)
- (let_keyword꞉ YulLetKeyword): "let" # (63..66)
- (names꞉ YulPaths): # " ufixed8x0\n" (66..77)
- (item꞉ YulPath): # " ufixed8x0\n" (66..77)
- (item꞉ YulPathComponent): # " ufixed8x0\n" (66..77)
- (leading_trivia꞉ Whitespace): " " # (66..67)
- (variant꞉ YulIdentifier): "ufixed8x0" # (67..76)
- (trailing_trivia꞉ EndOfLine): "\n" # (76..77)
- (leading_trivia꞉ Whitespace): " " # (66..67)
- (names꞉ YulIdentifier): "ufixed8x0" # (67..76)
- (trailing_trivia꞉ EndOfLine): "\n" # (76..77)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Tree:
- (leading_trivia꞉ SingleLineComment): "// This form is reserved only since 0.4.14 until 0..." # (0..62)
- (leading_trivia꞉ EndOfLine): "\n" # (62..63)
- (let_keyword꞉ YulLetKeyword): "let" # (63..66)
- (names꞉ YulPaths): # " ufixed8x0\n" (66..77)
- (item꞉ YulPath): # " ufixed8x0\n" (66..77)
- (item꞉ YulPathComponent): # " ufixed8x0\n" (66..77)
- (leading_trivia꞉ Whitespace): " " # (66..67)
- (variant꞉ YulIdentifier): "ufixed8x0" # (67..76)
- (trailing_trivia꞉ EndOfLine): "\n" # (76..77)
- (leading_trivia꞉ Whitespace): " " # (66..67)
- (names꞉ YulIdentifier): "ufixed8x0" # (67..76)
- (trailing_trivia꞉ EndOfLine): "\n" # (76..77)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Tree:
- (leading_trivia꞉ SingleLineComment): "// This form is always reserved until 0.7.1 in Yul..." # (0..51)
- (leading_trivia꞉ EndOfLine): "\n" # (51..52)
- (let_keyword꞉ YulLetKeyword): "let" # (52..55)
- (names꞉ YulPaths): # " ufixed8x8\n" (55..66)
- (item꞉ YulPath): # " ufixed8x8\n" (55..66)
- (item꞉ YulPathComponent): # " ufixed8x8\n" (55..66)
- (leading_trivia꞉ Whitespace): " " # (55..56)
- (variant꞉ YulIdentifier): "ufixed8x8" # (56..65)
- (trailing_trivia꞉ EndOfLine): "\n" # (65..66)
- (leading_trivia꞉ Whitespace): " " # (55..56)
- (names꞉ YulIdentifier): "ufixed8x8" # (56..65)
- (trailing_trivia꞉ EndOfLine): "\n" # (65..66)

0 comments on commit ce88cb7

Please sign in to comment.