Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
awelc committed Apr 19, 2024
1 parent a8acb98 commit 7ee7c75
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
17 changes: 16 additions & 1 deletion external-crates/move/crates/move-analyzer/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6856,13 +6856,28 @@ fn partial_dot_test() {
"PartialDot::M1::AnotherStruct\nanother_field: PartialDot::M1::SomeStruct",
Some((1, 18, "M1.move")),
);
// struct-typed second part of incomplete dot chain `s.another_field.` (followed by a list of
// parameters and a semi-colon: `s.another_field.(7, 42);`)
assert_use_def(
mod_symbols,
&symbols,
2,
14,
22,
"M1.move",
6,
8,
"M1.move",
"PartialDot::M1::AnotherStruct\nanother_field: PartialDot::M1::SomeStruct",
Some((1, 18, "M1.move")),
);
// struct-typed first part of incomplete dot chain `s.` (no `;` but followed by `}` on the next
// line)
assert_use_def(
mod_symbols,
&symbols,
1,
14,
15,
20,
"M1.move",
9,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module PartialDot::M1 {
let _tmp2 = s.another_field.;
let _tmp3 = s.another_field.
let _tmp4 = s; // statement skipped due to unexpected `let`
let _tmp5 = s.
let _tmp5 = s.another_field.(7, 42);
let _tmp6 = s.
}
}
16 changes: 13 additions & 3 deletions external-crates/move/crates/move-compiler/src/parser/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ fn report_name_migration(context: &mut Context, name: &str, loc: Loc) {

// Parse an identifier:
// Identifier = <IdentifierValue>
//
// Expects the current token to be Tok::Identifier or Tok::RestrictedIdentifier and returns
// `Syntax::UnexpectedToken` for the current token if it is not.
fn parse_identifier(context: &mut Context) -> Result<Name, Box<Diagnostic>> {
let id: Symbol = match context.tokens.peek() {
Tok::Identifier => context.tokens.content().into(),
Expand All @@ -568,7 +571,7 @@ fn parse_identifier(context: &mut Context) -> Result<Name, Box<Diagnostic>> {
}
};
let start_loc = context.tokens.start_loc();
context.tokens.advance()?;
context.advance();
let end_loc = context.tokens.previous_end_loc();
Ok(spanned(context.tokens.file_hash(), start_loc, end_loc, id))
}
Expand Down Expand Up @@ -2589,8 +2592,15 @@ fn parse_dot_or_index_chain(context: &mut Context) -> Result<Exp, Box<Diagnostic
}
}
_ => match parse_identifier(context) {
Err(diag) => {
context.add_diag(*diag);
Err(_) => {
// if it's neither a number (checked above) nor identifier, it conveys
// more information to the developer to signal that both are a
// possibility here (rather than just identifier which would be signaled
// if we kept the returned diagnostic)
context.add_diag(*unexpected_token_error(
context.tokens,
"an identifier or a decimal number",
));
Exp_::DotUnresolved(first_token_loc, Box::new(lhs))
}
Ok(n) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E01002]: unexpected token
│ ^
│ │
│ Unexpected ';'
│ Expected an identifier
│ Expected an identifier or a decimal number

error[E01002]: unexpected token
┌─ tests/move_2024/parser/dot_incomplete.move:13:37
Expand All @@ -14,7 +14,7 @@ error[E01002]: unexpected token
│ ^
│ │
│ Unexpected ';'
│ Expected an identifier
│ Expected an identifier or a decimal number

error[E01002]: unexpected token
┌─ tests/move_2024/parser/dot_incomplete.move:15:9
Expand All @@ -23,7 +23,7 @@ error[E01002]: unexpected token
│ ^^^
│ │
│ Unexpected 'let'
│ Expected an identifier
│ Expected an identifier or a decimal number

error[E01002]: unexpected token
┌─ tests/move_2024/parser/dot_incomplete.move:17:5
Expand All @@ -32,5 +32,5 @@ error[E01002]: unexpected token
│ ^
│ │
│ Unexpected '}'
│ Expected an identifier
│ Expected an identifier or a decimal number

0 comments on commit 7ee7c75

Please sign in to comment.