Skip to content

Commit 2e8eedc

Browse files
authored
[Compiler] Fix parse error when parsing for loops
1 parent 19869cb commit 2e8eedc

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

third_party/move/move-compiler/src/parser/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ impl<'input> Lexer<'input> {
356356
let offset = self.text.len() - text.len();
357357
let (found_token, length) = find_token(self.file_hash, text, offset)?;
358358
token = found_token;
359-
current_offset += length;
359+
current_offset = offset + length;
360360
}
361361
Ok(token)
362362
}

third_party/move/move-compiler/src/parser/syntax.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ fn parse_term(context: &mut Context) -> Result<Exp, Box<Diagnostic>> {
947947
},
948948
Tok::Identifier
949949
if context.tokens.content() == FOR_IDENT
950-
&& matches!(context.tokens.lookahead_nth(1), Ok(Tok::LParen))
951-
&& matches!(context.tokens.lookahead_nth(3), Ok(Tok::Identifier)) =>
950+
&& matches!(context.tokens.lookahead_nth(0), Ok(Tok::LParen))
951+
&& matches!(context.tokens.lookahead_nth(2), Ok(Tok::Identifier)) =>
952952
{
953953
let (control_exp, _) = parse_for_loop(context)?;
954954
// for loop isn't useful in an expression, so we ignore second result from
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//# run
2+
script {
3+
fun main(): () {
4+
for/**/( i in 0..10) {};
5+
for/**/ ( i in 0..10) {};
6+
for /**/( i in 0..10) {};
7+
for /**/ ( i in 0..10) {};
8+
}
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//# run
2+
script {
3+
fun main(): () {
4+
for( i in 0..10) {};
5+
}
6+
}

0 commit comments

Comments
 (0)