Skip to content
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

Fix panic during malformed empty interpolated string #333

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Luau: added support for user defined type functions (rfc: https://github.com/luau-lang/rfcs/blob/master/docs/user-defined-type-functions.md)

### Fixed
- Fixed a panic when parsing a malformed empty interpolated string, e.g. ``print(`{}`)``

## [1.1.2] - 2024-11-17

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion full-moon/src/ast/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ fn parse_primary_expression(state: &mut ParserState) -> ParserResult<Expression>
))
}

other => unreachable!("unexpected interpolated string kind: {other:?}"),
_ => ParserResult::NotFound,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
source: full-moon/tests/fail_cases.rs
expression: result.ast()
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
nodes:
stmts:
- - FunctionCall:
prefix:
Name:
leading_trivia: []
token:
start_position:
bytes: 0
line: 1
character: 1
end_position:
bytes: 5
line: 1
character: 6
token_type:
type: Identifier
identifier: print
trailing_trivia: []
suffixes:
- Call:
AnonymousCall:
Parentheses:
parentheses:
tokens:
- leading_trivia: []
token:
start_position:
bytes: 5
line: 1
character: 6
end_position:
bytes: 6
line: 1
character: 7
token_type:
type: Symbol
symbol: (
trailing_trivia: []
- leading_trivia: []
token:
start_position:
bytes: 10
line: 1
character: 11
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Symbol
symbol: )
trailing_trivia: []
arguments:
pairs:
- End:
InterpolatedString:
segments: []
last_string:
leading_trivia: []
token:
start_position:
bytes: 6
line: 1
character: 7
end_position:
bytes: 8
line: 1
character: 9
token_type:
type: InterpolatedString
literal: ""
kind: Begin
trailing_trivia: []
- ~
eof:
leading_trivia: []
token:
start_position:
bytes: 11
line: 1
character: 12
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Eof
trailing_trivia: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: full-moon/tests/fail_cases.rs
expression: ast.to_string()
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
"print(`{)"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I like this resolved AST to string

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: full-moon/tests/fail_cases.rs
expression: "String::from_utf8(output.into_inner()).unwrap()"
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
error[ast]: expected expression after `{`
┌─ source.lua:1:7
1 │ print(`{}`)
│ ^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: full-moon/tests/fail_cases.rs
expression: result.errors()
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
- AstError:
token:
start_position:
bytes: 6
line: 1
character: 7
end_position:
bytes: 8
line: 1
character: 9
token_type:
type: InterpolatedString
literal: ""
kind: Begin
additional: "expected expression after `{`"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print(`{}`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
source: full-moon/tests/fail_cases.rs
expression: tokens
input_file: full-moon/tests/roblox_cases/fail/parser/string_interpolation_empty
---
- start_position:
bytes: 0
line: 1
character: 1
end_position:
bytes: 5
line: 1
character: 6
token_type:
type: Identifier
identifier: print
- start_position:
bytes: 5
line: 1
character: 6
end_position:
bytes: 6
line: 1
character: 7
token_type:
type: Symbol
symbol: (
- start_position:
bytes: 6
line: 1
character: 7
end_position:
bytes: 8
line: 1
character: 9
token_type:
type: InterpolatedString
literal: ""
kind: Begin
- start_position:
bytes: 8
line: 1
character: 9
end_position:
bytes: 10
line: 1
character: 11
token_type:
type: InterpolatedString
literal: ""
kind: End
- start_position:
bytes: 10
line: 1
character: 11
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Symbol
symbol: )
- start_position:
bytes: 11
line: 1
character: 12
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Eof
Loading