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 nested tuple access #3945

Merged
merged 2 commits into from
Dec 3, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@
not emit a warning if an @external function had been referenced.
([Richard Viney](https://github.com/richard-viney))

- Fixed a bug where nested tuple access would not be parsed correctly when
the left-hand side was a function call.
([Surya Rose](https://github.com/GearsDatapacks))

## v1.6.1 - 2024-11-19

### Bug fixed
Expand Down
5 changes: 2 additions & 3 deletions compiler-core/src/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ where
check_for_minus = true;
let name = self.lex_name()?;
self.emit(name);
self.maybe_lex_dot_access()?;
} else if self.is_number_start(c, self.chr1) {
check_for_minus = true;
let num = self.lex_number()?;
Expand Down Expand Up @@ -437,6 +436,7 @@ where
} else {
let tok_end = self.get_pos();
self.emit((tok_start, Token::Dot, tok_end));
self.maybe_lex_dot_access()?;
}
}
'#' => {
Expand Down Expand Up @@ -647,8 +647,7 @@ where
fn maybe_lex_dot_access(&mut self) -> Result<(), LexicalError> {
// It can be nested like: `tuple.1.2.3.4`
loop {
if Some('.') == self.chr0 && matches!(self.chr1, Some('0'..='9')) {
self.eat_single_char(Token::Dot);
if matches!(self.chr0, Some('0'..='9')) {
let number = self.lex_int_number()?;
self.emit(number);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: compiler-core/src/parse/tests.rs
expression: tuple().0.1
---
[
Expression(
TupleIndex {
location: SrcSpan {
start: 0,
end: 11,
},
index: 1,
tuple: TupleIndex {
location: SrcSpan {
start: 0,
end: 9,
},
index: 0,
tuple: Call {
location: SrcSpan {
start: 0,
end: 7,
},
fun: Var {
location: SrcSpan {
start: 0,
end: 5,
},
name: "tuple",
},
arguments: [],
},
},
},
),
]
6 changes: 6 additions & 0 deletions compiler-core/src/parse/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,3 +1672,9 @@ type Wibble {
"#
);
}

#[test]
// https://github.com/gleam-lang/gleam/issues/3870
fn nested_tuple_access_after_function() {
assert_parse!("tuple().0.1");
}
Loading