Skip to content

Commit

Permalink
Forbid some empty separated lists in v2 (#667)
Browse files Browse the repository at this point in the history
Part of #652

These are a bug-fixes along with regression tests added for each case,
we use a definition from v0/v1 for these.
  • Loading branch information
Xanewok authored Nov 22, 2023
1 parent a90a6fe commit 54af80d
Show file tree
Hide file tree
Showing 17 changed files with 268 additions and 8 deletions.
19 changes: 11 additions & 8 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ codegen_language_macros::compile!(Language(
Separated(
name = ImportDeconstructionFields,
separated = ImportDeconstructionField,
separator = Comma,
allow_empty = true
separator = Comma
),
Struct(
name = ImportDeconstructionField,
Expand Down Expand Up @@ -335,8 +334,7 @@ codegen_language_macros::compile!(Language(
name = UsingDeconstructionFields,
separated = UsingDeconstructionField,
separator = Comma,
enabled = From("0.8.13"),
allow_empty = true
enabled = From("0.8.13")
),
Struct(
name = UsingDeconstructionField,
Expand Down Expand Up @@ -2377,14 +2375,20 @@ codegen_language_macros::compile!(Language(
),
Struct(
name = OverrideSpecifier,
fields = (
override_keyword = Required(Terminal([OverrideKeyword])),
overridden = Optional(kind = NonTerminal(OverridePathsDeclaration))
)
),
Struct(
name = OverridePathsDeclaration,
error_recovery = FieldsErrorRecovery(
delimiters =
FieldDelimiters(open = open_paren, close = close_paren)
),
fields = (
override_keyword = Required(Terminal([OverrideKeyword])),
open_paren = Required(Terminal([OpenParen])),
overridden = Optional(kind = NonTerminal(OverridePaths)),
paths = Required(NonTerminal(OverridePaths)),
close_paren = Required(Terminal([CloseParen]))
)
),
Expand Down Expand Up @@ -2904,8 +2908,7 @@ codegen_language_macros::compile!(Language(
Separated(
name = TupleMembersDeconstruction,
separated = TupleMemberDeconstruction,
separator = Comma,
allow_empty = true
separator = Comma
),
Struct(
name = TupleMemberDeconstruction,
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ function some() public virtual override returns (uint256) { │ 0..59
2 │ return 1; │ 60..70
3 │ } │ 71..72
Errors: []

Tree:
- FunctionDefinition (Rule): # 0..73 "function some() public virtual override returns (u..."
- FunctionKeyword (Token): "function" # 0..8
- Identifier (Token): "some" # 9..13
- ParametersDeclaration (Rule): # 13..15 "()"
- OpenParen (Token): "(" # 13..14
- CloseParen (Token): ")" # 14..15
- FunctionAttributes (Rule): # 15..39 " public virtual override"
- PublicKeyword (Token): "public" # 16..22
- ModifierInvocation (Rule): # 22..30 " virtual"
- IdentifierPath (Rule): # 22..30 " virtual"
- Identifier (Token): "virtual" # 23..30
- ModifierInvocation (Rule): # 30..39 " override"
- IdentifierPath (Rule): # 30..39 " override"
- Identifier (Token): "override" # 31..39
- ReturnsDeclaration (Rule): # 39..57 " returns (uint256)"
- ReturnsKeyword (Token): "returns" # 40..47
- ParametersDeclaration (Rule): # 47..57 " (uint256)"
- OpenParen (Token): "(" # 48..49
- Parameters (Rule): # 49..56 "uint256"
- Parameter (Rule): # 49..56 "uint256"
- TypeName (Rule): # 49..56 "uint256"
- UintKeyword (Token): "uint256" # 49..56
- CloseParen (Token): ")" # 56..57
- Block (Rule): # 57..73 " {\n\treturn 1;\n}\n"
- OpenBrace (Token): "{" # 58..59
- Statements (Rule): # 60..71 "\treturn 1;\n"
- ReturnStatement (Rule): # 60..71 "\treturn 1;\n"
- ReturnKeyword (Token): "return" # 61..67
- Expression (Rule): # 67..69 " 1"
- DecimalNumberExpression (Rule): # 67..69 " 1"
- DecimalLiteral (Token): "1" # 68..69
- Semicolon (Token): ";" # 69..70
- CloseBrace (Token): "}" # 71..72
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ function some() public virtual override returns (uint256) { │ 0..59
2 │ return 1; │ 60..70
3 │ } │ 71..72
Errors: []

Tree:
- FunctionDefinition (Rule): # 0..73 "function some() public virtual override returns (u..."
- FunctionKeyword (Token): "function" # 0..8
- Identifier (Token): "some" # 9..13
- ParametersDeclaration (Rule): # 13..15 "()"
- OpenParen (Token): "(" # 13..14
- CloseParen (Token): ")" # 14..15
- FunctionAttributes (Rule): # 15..39 " public virtual override"
- PublicKeyword (Token): "public" # 16..22
- ModifierInvocation (Rule): # 22..30 " virtual"
- IdentifierPath (Rule): # 22..30 " virtual"
- Identifier (Token): "virtual" # 23..30
- OverrideSpecifier (Rule): # 30..39 " override"
- OverrideKeyword (Token): "override" # 31..39
- ReturnsDeclaration (Rule): # 39..57 " returns (uint256)"
- ReturnsKeyword (Token): "returns" # 40..47
- ParametersDeclaration (Rule): # 47..57 " (uint256)"
- OpenParen (Token): "(" # 48..49
- Parameters (Rule): # 49..56 "uint256"
- Parameter (Rule): # 49..56 "uint256"
- TypeName (Rule): # 49..56 "uint256"
- UintKeyword (Token): "uint256" # 49..56
- CloseParen (Token): ")" # 56..57
- Block (Rule): # 57..73 " {\n\treturn 1;\n}\n"
- OpenBrace (Token): "{" # 58..59
- Statements (Rule): # 60..71 "\treturn 1;\n"
- ReturnStatement (Rule): # 60..71 "\treturn 1;\n"
- ReturnKeyword (Token): "return" # 61..67
- Expression (Rule): # 67..69 " 1"
- DecimalNumberExpression (Rule): # 67..69 " 1"
- DecimalLiteral (Token): "1" # 68..69
- Semicolon (Token): ";" # 69..70
- CloseBrace (Token): "}" # 71..72
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ function some() public virtual override returns (uint256) { │ 0..59
2 │ return 1; │ 60..70
3 │ } │ 71..72
Errors: []

Tree:
- FunctionDefinition (Rule): # 0..73 "function some() public virtual override returns (u..."
- FunctionKeyword (Token): "function" # 0..8
- Identifier (Token): "some" # 9..13
- ParametersDeclaration (Rule): # 13..15 "()"
- OpenParen (Token): "(" # 13..14
- CloseParen (Token): ")" # 14..15
- FunctionAttributes (Rule): # 15..39 " public virtual override"
- PublicKeyword (Token): "public" # 16..22
- VirtualKeyword (Token): "virtual" # 23..30
- OverrideSpecifier (Rule): # 30..39 " override"
- OverrideKeyword (Token): "override" # 31..39
- ReturnsDeclaration (Rule): # 39..57 " returns (uint256)"
- ReturnsKeyword (Token): "returns" # 40..47
- ParametersDeclaration (Rule): # 47..57 " (uint256)"
- OpenParen (Token): "(" # 48..49
- Parameters (Rule): # 49..56 "uint256"
- Parameter (Rule): # 49..56 "uint256"
- TypeName (Rule): # 49..56 "uint256"
- UintKeyword (Token): "uint256" # 49..56
- CloseParen (Token): ")" # 56..57
- Block (Rule): # 57..73 " {\n\treturn 1;\n}\n"
- OpenBrace (Token): "{" # 58..59
- Statements (Rule): # 60..71 "\treturn 1;\n"
- ReturnStatement (Rule): # 60..71 "\treturn 1;\n"
- ReturnKeyword (Token): "return" # 61..67
- Expression (Rule): # 67..69 " 1"
- DecimalNumberExpression (Rule): # 67..69 " 1"
- DecimalLiteral (Token): "1" # 68..69
- Semicolon (Token): ";" # 69..70
- CloseBrace (Token): "}" # 71..72
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function some() public virtual override returns (uint256) {
return 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ // Empty imports are not valid │ 0..30
2 │ import {} from "foo"; │ 31..52
Errors: # 1 total
- >
Error: Expected Identifier.
╭─[crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_empty/input.sol:2:9]
2 │ import {} from "foo";
│ │
│ ╰─ Error occurred here.
───╯
Tree:
- ImportDirective (Rule): # 0..53 '// Empty imports are not valid\nimport {} from "foo...'
- LeadingTrivia (Rule): # 0..31 "// Empty imports are not valid\n"
- SingleLineComment (Trivia): "// Empty imports are not valid" # 0..30
- ImportKeyword (Token): "import" # 31..37
- DeconstructionImport (Rule): # 37..51 ' {} from "foo"'
- OpenBrace (Token): "{" # 38..39
- SKIPPED (Token): "" # 39..39
- CloseBrace (Token): "}" # 39..40
- FromKeyword (Token): "from" # 41..45
- AsciiStringLiteral (Token): '"foo"' # 46..51
- Semicolon (Token): ";" # 51..52
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Empty imports are not valid
import {} from "foo";
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ // TODO(#671): Tuple expressions can't be empty │ 0..47
2 │ () = (); │ 48..56
Errors: []

Tree:
- TupleDeconstructionStatement (Rule): # 0..57 "// TODO(#671): Tuple expressions can't be empty\n()..."
- LeadingTrivia (Rule): # 0..48 "// TODO(#671): Tuple expressions can't be empty\n"
- SingleLineComment (Trivia): "// TODO(#671): Tuple expressions can't be empty" # 0..47
- OpenParen (Token): "(" # 48..49
- TupleMembers (Rule): # 49..49
- TupleMember (Rule): [] # 49..49
- CloseParen (Token): ")" # 49..50
- Equal (Token): "=" # 51..52
- Expression (Rule): # 52..55 " ()"
- TupleExpression (Rule): # 52..55 " ()"
- OpenParen (Token): "(" # 53..54
- TupleValues (Rule): [] # 54..54
- CloseParen (Token): ")" # 54..55
- Semicolon (Token): ";" # 55..56
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO(#671): Tuple expressions can't be empty
() = ();
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ // Empty using symbols list is not valid │ 0..40
2 │ using {} for *; │ 41..56
Errors: # 1 total
- >
Error: Expected Identifier.
╭─[crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/input.sol:2:7]
2 │ using {} for *;
│ ────┬───
│ ╰───── Error occurred here.
───╯
Tree:
- UsingDirective (Rule): # 0..57 "// Empty using symbols list is not valid\nusing {} ..."
- LeadingTrivia (Rule): # 0..41 "// Empty using symbols list is not valid\n"
- SingleLineComment (Trivia): "// Empty using symbols list is not valid" # 0..40
- UsingKeyword (Token): "using" # 41..46
- SKIPPED (Token): "{} for *" # 47..55
- Semicolon (Token): ";" # 55..56
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ // Empty using symbols list is not valid │ 0..40
2 │ using {} for *; │ 41..56
Errors: # 1 total
- >
Error: Expected Identifier.
╭─[crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/input.sol:2:8]
2 │ using {} for *;
│ │
│ ╰─ Error occurred here.
───╯
Tree:
- UsingDirective (Rule): # 0..57 "// Empty using symbols list is not valid\nusing {} ..."
- LeadingTrivia (Rule): # 0..41 "// Empty using symbols list is not valid\n"
- SingleLineComment (Trivia): "// Empty using symbols list is not valid" # 0..40
- UsingKeyword (Token): "using" # 41..46
- UsingDirectiveDeconstruction (Rule): # 46..49 " {}"
- OpenBrace (Token): "{" # 47..48
- SKIPPED (Token): "" # 48..48
- CloseBrace (Token): "}" # 48..49
- ForKeyword (Token): "for" # 50..53
- Asterisk (Token): "*" # 54..55
- Semicolon (Token): ";" # 55..56
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Empty using symbols list is not valid
using {} for *;
1 change: 1 addition & 0 deletions crates/solidity/testing/utils/src/cst_snapshots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ fn write_node<W: Write>(

let (node_value, node_comment) = if range.is_empty() {
let preview = match node {
cst::Node::Rule(_) if !node.children().is_empty() => "",
cst::Node::Rule(_) => " []",
cst::Node::Token(_) => " \"\"",
};
Expand Down

0 comments on commit 54af80d

Please sign in to comment.