diff --git a/compiler/noirc_frontend/src/ast/statement.rs b/compiler/noirc_frontend/src/ast/statement.rs index c1df5451c17..7de4c37c1b9 100644 --- a/compiler/noirc_frontend/src/ast/statement.rs +++ b/compiler/noirc_frontend/src/ast/statement.rs @@ -179,7 +179,7 @@ impl StatementKind { } } -#[derive(Eq, Debug, Clone, Default)] +#[derive(Eq, Debug, Clone)] pub struct Ident(Located); impl PartialEq for Ident { diff --git a/compiler/noirc_frontend/src/parser/parser.rs b/compiler/noirc_frontend/src/parser/parser.rs index 9a4b60033e5..0862e408ea3 100644 --- a/compiler/noirc_frontend/src/parser/parser.rs +++ b/compiler/noirc_frontend/src/parser/parser.rs @@ -530,11 +530,14 @@ impl<'a> Parser<'a> { } fn location_at_previous_token_end(&self) -> Location { - Location::new(self.span_at_previous_token_end(), self.previous_token_location.file) + let span_at_previous_token_end = Span::from( + self.previous_token_location.span.end()..self.previous_token_location.span.end(), + ); + Location::new(span_at_previous_token_end, self.previous_token_location.file) } - fn span_at_previous_token_end(&self) -> Span { - Span::from(self.previous_token_location.span.end()..self.previous_token_location.span.end()) + fn unknown_ident_at_previous_token_end(&self) -> Ident { + Ident::new("(unknown)".to_string(), self.location_at_previous_token_end()) } fn expected_identifier(&mut self) { diff --git a/compiler/noirc_frontend/src/parser/parser/enums.rs b/compiler/noirc_frontend/src/parser/parser/enums.rs index 44076677ae6..8cd6a1ba249 100644 --- a/compiler/noirc_frontend/src/parser/parser/enums.rs +++ b/compiler/noirc_frontend/src/parser/parser/enums.rs @@ -26,7 +26,7 @@ impl Parser<'_> { let Some(name) = self.eat_ident() else { self.expected_identifier(); return self.empty_enum( - Ident::default(), + self.unknown_ident_at_previous_token_end(), attributes, visibility, Vec::new(), @@ -119,6 +119,8 @@ impl Parser<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ ast::{IntegerBitSize, NoirEnumeration, UnresolvedGeneric, UnresolvedTypeData}, parse_program_with_dummy_file, @@ -258,6 +260,6 @@ mod tests { assert_eq!(errors.len(), 1); let error = &errors[0]; - assert_eq!(error.to_string(), "Expected an identifier but found '42'"); + assert_snapshot!(error.to_string(), @"Expected an identifier but found '42'"); } } diff --git a/compiler/noirc_frontend/src/parser/parser/expression.rs b/compiler/noirc_frontend/src/parser/parser/expression.rs index dbf77358b6b..5475898847b 100644 --- a/compiler/noirc_frontend/src/parser/parser/expression.rs +++ b/compiler/noirc_frontend/src/parser/parser/expression.rs @@ -1015,6 +1015,7 @@ impl Parser<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; use strum::IntoEnumIterator; use crate::{ @@ -1281,7 +1282,7 @@ mod tests { let mut parser = Parser::for_str_with_dummy_file(&src); parser.parse_expression(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected an expression but found end of input"); + assert_snapshot!(error.to_string(), @"Expected an expression but found end of input"); } #[test] @@ -1653,7 +1654,7 @@ mod tests { let expr = parser.parse_expression_or_error(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a ':' but found '='"); + assert_snapshot!(error.to_string(), @"Expected a ':' but found '='"); let ExpressionKind::Constructor(mut constructor) = expr.kind else { panic!("Expected constructor"); @@ -1681,7 +1682,7 @@ mod tests { let expr = parser.parse_expression_or_error(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a ':' but found '::'"); + assert_snapshot!(error.to_string(), @"Expected a ':' but found '::'"); let ExpressionKind::Constructor(mut constructor) = expr.kind else { panic!("Expected constructor"); @@ -1719,7 +1720,7 @@ mod tests { assert_eq!(expr.to_string(), "1"); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected an identifier but found '2'"); + assert_snapshot!(error.to_string(), @"Expected an identifier but found '2'"); } #[test] @@ -1747,7 +1748,7 @@ mod tests { assert_eq!(expr.to_string(), "2"); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected an identifier but found '2'"); + assert_snapshot!(error.to_string(), @"Expected an identifier but found '2'"); } #[test] @@ -1821,7 +1822,7 @@ mod tests { let mut parser = Parser::for_str_with_dummy_file(&src); parser.parse_expression(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a type but found end of input"); + assert_snapshot!(error.to_string(), @"Expected a type but found end of input"); } #[test] diff --git a/compiler/noirc_frontend/src/parser/parser/function.rs b/compiler/noirc_frontend/src/parser/parser/function.rs index 69d9caf1e00..bf6ab4396a7 100644 --- a/compiler/noirc_frontend/src/parser/parser/function.rs +++ b/compiler/noirc_frontend/src/parser/parser/function.rs @@ -87,9 +87,17 @@ impl Parser<'_> { allow_optional_body: bool, allow_self: bool, ) -> FunctionDefinitionWithOptionalBody { - let Some(name) = self.eat_ident() else { + let name = if let Some(name) = self.eat_ident() { + name + } else if self.at(Token::LeftParen) || self.at(Token::Less) { + // If it's `fn (...` or `fn <...` we assume the user missed the function name but a function + // definition follows. This can happen if the user is currently renaming a function by first + // erasing the name. self.expected_identifier(); - return empty_function(self.previous_token_location); + self.unknown_ident_at_previous_token_end() + } else { + self.expected_identifier(); + return empty_function(self.location_at_previous_token_end()); }; let generics = self.parse_generics_allowing_trait_bounds(); @@ -320,15 +328,14 @@ impl Parser<'_> { } fn empty_function(location: Location) -> FunctionDefinitionWithOptionalBody { - let span = Span::from(location.span.end()..location.span.end()); FunctionDefinitionWithOptionalBody { - name: Ident::default(), + name: Ident::new(String::new(), location), generics: Vec::new(), parameters: Vec::new(), body: None, - location: Location::new(span, location.file), + location, where_clause: Vec::new(), - return_type: FunctionReturnType::Default(Location::new(span, location.file)), + return_type: FunctionReturnType::Default(location), return_visibility: Visibility::Private, } } @@ -339,6 +346,8 @@ fn empty_body() -> BlockExpression { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ ast::{ ExpressionKind, IntegerBitSize, ItemVisibility, NoirFunction, StatementKind, @@ -499,7 +508,7 @@ mod tests { assert_eq!(noir_function.parameters().len(), 1); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected a pattern but found '1'"); + assert_snapshot!(error.to_string(), @"Expected a pattern but found '1'"); } #[test] @@ -535,7 +544,7 @@ mod tests { assert_eq!(noir_function.parameters().len(), 2); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected a type but found ','"); + assert_snapshot!(error.to_string(), @"Expected a type but found ','"); } #[test] @@ -568,7 +577,7 @@ mod tests { let (src, span) = get_source_with_error_span(src); let (mut module, errors) = parse_program_with_dummy_file(&src); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected a type but found 'mut'"); + assert_snapshot!(error.to_string(), @"Expected a type but found 'mut'"); assert_eq!(module.items.len(), 1); let item = module.items.remove(0); @@ -653,7 +662,7 @@ mod tests { let _ = parser.parse_program(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Unexpected 'struct', expected one of 'where', '{', '->'"); + assert_snapshot!(error.to_string(), @"Unexpected 'struct', expected one of 'where', '{', '->'"); } #[test] @@ -667,7 +676,7 @@ mod tests { let _ = parser.parse_program(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Unexpected 'struct', expected one of 'where', '{'"); + assert_snapshot!(error.to_string(), @"Unexpected 'struct', expected one of 'where', '{'"); } #[test] @@ -681,6 +690,20 @@ mod tests { let _ = parser.parse_program(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a '{' but found 'struct'"); + assert_snapshot!(error.to_string(), @"Expected a '{' but found 'struct'"); + } + + #[test] + fn errors_on_missing_function_name() { + let src = " + fn () {} + ^ + "; + let (src, span) = get_source_with_error_span(src); + let mut parser = Parser::for_str_with_dummy_file(&src); + let _ = parser.parse_program(); + + let error = get_single_error(&parser.errors, span); + assert_snapshot!(error.to_string(), @"Expected an identifier but found '('"); } } diff --git a/compiler/noirc_frontend/src/parser/parser/global.rs b/compiler/noirc_frontend/src/parser/parser/global.rs index e33a8f3dd5a..ffa5a0c19a3 100644 --- a/compiler/noirc_frontend/src/parser/parser/global.rs +++ b/compiler/noirc_frontend/src/parser/parser/global.rs @@ -28,8 +28,9 @@ impl Parser<'_> { let Some(ident) = self.eat_ident() else { self.eat_semicolon(); let location = self.location_at_previous_token_end(); + let ident = self.unknown_ident_at_previous_token_end(); return LetStatement { - pattern: ident_to_pattern(Ident::default(), mutable), + pattern: ident_to_pattern(ident, mutable), r#type: UnresolvedType { typ: UnresolvedTypeData::Unspecified, location }, expression: Expression { kind: ExpressionKind::Error, location }, attributes, @@ -68,6 +69,7 @@ fn ident_to_pattern(ident: Ident, mutable: bool) -> Pattern { #[cfg(test)] mod tests { use acvm::FieldElement; + use insta::assert_snapshot; use crate::{ ast::{ @@ -168,7 +170,7 @@ mod tests { let (src, span) = get_source_with_error_span(src); let (_, errors) = parse_program_with_dummy_file(&src); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected a ';' but found end of input"); + assert_snapshot!(error.to_string(), @"Expected a ';' but found end of input"); } #[test] diff --git a/compiler/noirc_frontend/src/parser/parser/impls.rs b/compiler/noirc_frontend/src/parser/parser/impls.rs index 31e5e32a50f..6c40c970644 100644 --- a/compiler/noirc_frontend/src/parser/parser/impls.rs +++ b/compiler/noirc_frontend/src/parser/parser/impls.rs @@ -2,7 +2,7 @@ use noirc_errors::Location; use crate::{ ast::{ - Documented, Expression, ExpressionKind, Ident, ItemVisibility, NoirFunction, NoirTraitImpl, + Documented, Expression, ExpressionKind, ItemVisibility, NoirFunction, NoirTraitImpl, TraitImplItem, TraitImplItemKind, TypeImpl, UnresolvedGeneric, UnresolvedType, UnresolvedTypeData, }, @@ -156,10 +156,9 @@ impl Parser<'_> { self.expected_identifier(); self.eat_semicolons(); let location = self.location_at_previous_token_end(); - return Some(TraitImplItemKind::Type { - name: Ident::default(), - alias: UnresolvedType { typ: UnresolvedTypeData::Error, location }, - }); + let name = self.unknown_ident_at_previous_token_end(); + let alias = UnresolvedType { typ: UnresolvedTypeData::Error, location }; + return Some(TraitImplItemKind::Type { name, alias }); }; let alias = if self.eat_assign() { @@ -184,7 +183,7 @@ impl Parser<'_> { Some(name) => name, None => { self.expected_identifier(); - Ident::default() + self.unknown_ident_at_previous_token_end() } }; @@ -235,6 +234,8 @@ impl Parser<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ ast::{ ItemVisibility, NoirTraitImpl, Pattern, TraitImplItemKind, TypeImpl, UnresolvedTypeData, @@ -549,7 +550,7 @@ mod tests { assert_eq!(type_impl.methods.len(), 1); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected a function but found 'hello'"); + assert_snapshot!(error.to_string(), @"Expected a function but found 'hello'"); } #[test] @@ -569,7 +570,7 @@ mod tests { assert_eq!(trait_imp.items.len(), 1); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected a trait impl item but found 'hello'"); + assert_snapshot!(error.to_string(), @"Expected a trait impl item but found 'hello'"); } #[test] diff --git a/compiler/noirc_frontend/src/parser/parser/item.rs b/compiler/noirc_frontend/src/parser/parser/item.rs index 4a53664b182..7172f95f622 100644 --- a/compiler/noirc_frontend/src/parser/parser/item.rs +++ b/compiler/noirc_frontend/src/parser/parser/item.rs @@ -153,7 +153,18 @@ impl<'a> Parser<'a> { if let Some(is_contract) = self.eat_mod_or_contract() { self.comptime_mutable_and_unconstrained_not_applicable(modifiers); - return vec![self.parse_mod_or_contract(attributes, is_contract, modifiers.visibility)]; + if let Some(ident) = self.eat_ident() { + return vec![self.parse_mod_or_contract( + ident, + attributes, + is_contract, + modifiers.visibility, + )]; + }; + + self.expected_identifier(); + self.bump(); + self.eat_semicolons(); } if self.eat_keyword(Keyword::Struct) { @@ -261,6 +272,8 @@ impl<'a> Parser<'a> { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ parse_program_with_dummy_file, parser::{ @@ -279,7 +292,7 @@ mod tests { let (module, errors) = parse_program_with_dummy_file(&src); assert_eq!(module.items.len(), 2); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected an item but found 'hello'"); + assert_snapshot!(error.to_string(), @"Expected an item but found 'hello'"); } #[test] @@ -292,7 +305,7 @@ mod tests { let (module, errors) = parse_program_with_dummy_file(&src); assert_eq!(module.items.len(), 1); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected a '}' but found end of input"); + assert_snapshot!(error.to_string(), @"Expected a '}' but found end of input"); } #[test] @@ -375,4 +388,17 @@ mod tests { let reason = get_single_error(&parser.errors, span); assert_eq!(reason.to_string(), "Expected a 'fn' but found 'foo'"); } + + #[test] + fn errors_on_missing_mod_identifier() { + let src = " + mod ; fn foo() {} + ^ + "; + let (src, span) = get_source_with_error_span(src); + let (module, errors) = parse_program_with_dummy_file(&src); + assert_eq!(module.items.len(), 1); + let error = get_single_error(&errors, span); + assert_snapshot!(error.to_string(), @"Expected an identifier but found ';'"); + } } diff --git a/compiler/noirc_frontend/src/parser/parser/item_visibility.rs b/compiler/noirc_frontend/src/parser/parser/item_visibility.rs index 91ace6a62ce..c5ae825f7c5 100644 --- a/compiler/noirc_frontend/src/parser/parser/item_visibility.rs +++ b/compiler/noirc_frontend/src/parser/parser/item_visibility.rs @@ -36,6 +36,8 @@ impl Parser<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ ast::ItemVisibility, parser::{ @@ -73,7 +75,7 @@ mod tests { let visibility = parser.parse_item_visibility(); assert_eq!(visibility, ItemVisibility::Public); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a 'crate' but found end of input"); + assert_snapshot!(error.to_string(), @"Expected a 'crate' but found end of input"); } #[test] @@ -87,7 +89,7 @@ mod tests { let visibility = parser.parse_item_visibility(); assert_eq!(visibility, ItemVisibility::Public); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a 'crate' but found 'hello'"); + assert_snapshot!(error.to_string(), @"Expected a 'crate' but found 'hello'"); } #[test] fn parses_public_visibility_missing_paren_after_pub_crate() { @@ -100,7 +102,7 @@ mod tests { let visibility = parser.parse_item_visibility(); assert_eq!(visibility, ItemVisibility::PublicCrate); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a ')' but found end of input"); + assert_snapshot!(error.to_string(), @"Expected a ')' but found end of input"); } #[test] diff --git a/compiler/noirc_frontend/src/parser/parser/module.rs b/compiler/noirc_frontend/src/parser/parser/module.rs index cae0a328d75..ae67f141711 100644 --- a/compiler/noirc_frontend/src/parser/parser/module.rs +++ b/compiler/noirc_frontend/src/parser/parser/module.rs @@ -13,22 +13,13 @@ impl Parser<'_> { /// = ( 'mod' | 'contract' ) identifier ( '{' Module '}' | ';' ) pub(super) fn parse_mod_or_contract( &mut self, + ident: Ident, attributes: Vec<(Attribute, Location)>, is_contract: bool, visibility: ItemVisibility, ) -> ItemKind { let outer_attributes = self.validate_secondary_attributes(attributes); - let Some(ident) = self.eat_ident() else { - self.expected_identifier(); - return ItemKind::ModuleDecl(ModuleDeclaration { - visibility, - ident: Ident::default(), - outer_attributes, - has_semicolon: false, - }); - }; - if self.eat_left_brace() { let contents = self.parse_module( true, // nested diff --git a/compiler/noirc_frontend/src/parser/parser/path.rs b/compiler/noirc_frontend/src/parser/parser/path.rs index f27cce07b89..58a05a7b4f2 100644 --- a/compiler/noirc_frontend/src/parser/parser/path.rs +++ b/compiler/noirc_frontend/src/parser/parser/path.rs @@ -219,6 +219,8 @@ impl Parser<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ ast::{Path, PathKind}, parser::{ @@ -352,6 +354,6 @@ mod tests { assert!(path.is_none()); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected an identifier but found end of input"); + assert_snapshot!(error.to_string(), @"Expected an identifier but found end of input"); } } diff --git a/compiler/noirc_frontend/src/parser/parser/pattern.rs b/compiler/noirc_frontend/src/parser/parser/pattern.rs index e1468845ded..a462803c20f 100644 --- a/compiler/noirc_frontend/src/parser/parser/pattern.rs +++ b/compiler/noirc_frontend/src/parser/parser/pattern.rs @@ -249,6 +249,8 @@ impl Parser<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ ast::Pattern, parser::{ @@ -355,7 +357,7 @@ mod tests { let pattern = parser.parse_pattern_or_error(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a ':' but found '='"); + assert_snapshot!(error.to_string(), @"Expected a ':' but found '='"); let Pattern::Struct(path, mut patterns, _) = pattern else { panic!("Expected a struct pattern") diff --git a/compiler/noirc_frontend/src/parser/parser/statement.rs b/compiler/noirc_frontend/src/parser/parser/statement.rs index b017e46b511..6092ec5cb23 100644 --- a/compiler/noirc_frontend/src/parser/parser/statement.rs +++ b/compiler/noirc_frontend/src/parser/parser/statement.rs @@ -264,7 +264,7 @@ impl Parser<'_> { let Some(identifier) = self.eat_ident() else { self.expected_identifier(); - let identifier = Ident::default(); + let identifier = self.unknown_ident_at_previous_token_end(); return Some(self.empty_for_loop(identifier, start_location)); }; @@ -466,6 +466,8 @@ impl Parser<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ ast::{ExpressionKind, ForRange, LValue, Statement, StatementKind, UnresolvedTypeData}, parser::{ @@ -772,7 +774,7 @@ mod tests { let statement = parser.parse_statement_or_error(); assert!(matches!(statement.kind, StatementKind::Let(..))); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a statement but found ']'"); + assert_snapshot!(error.to_string(), @"Expected a statement but found ']'"); } #[test] diff --git a/compiler/noirc_frontend/src/parser/parser/structs.rs b/compiler/noirc_frontend/src/parser/parser/structs.rs index 876e45c3292..da4a2c5ae28 100644 --- a/compiler/noirc_frontend/src/parser/parser/structs.rs +++ b/compiler/noirc_frontend/src/parser/parser/structs.rs @@ -23,7 +23,7 @@ impl Parser<'_> { let Some(name) = self.eat_ident() else { self.expected_identifier(); return self.empty_struct( - Ident::default(), + self.unknown_ident_at_previous_token_end(), attributes, visibility, Vec::new(), @@ -128,6 +128,8 @@ impl Parser<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; + use crate::{ ast::{IntegerBitSize, NoirStruct, UnresolvedGeneric, UnresolvedTypeData}, parse_program_with_dummy_file, @@ -272,6 +274,6 @@ mod tests { assert_eq!(noir_struct.fields.len(), 1); let error = get_single_error(&errors, span); - assert_eq!(error.to_string(), "Expected an identifier but found '42'"); + assert_snapshot!(error.to_string(), @"Expected an identifier but found '42'"); } } diff --git a/compiler/noirc_frontend/src/parser/parser/traits.rs b/compiler/noirc_frontend/src/parser/parser/traits.rs index 0df6a495343..1486bdff0b0 100644 --- a/compiler/noirc_frontend/src/parser/parser/traits.rs +++ b/compiler/noirc_frontend/src/parser/parser/traits.rs @@ -177,7 +177,7 @@ impl Parser<'_> { Some(name) => name, None => { self.expected_identifier(); - Ident::default() + self.unknown_ident_at_previous_token_end() } }; @@ -196,7 +196,7 @@ impl Parser<'_> { Some(name) => name, None => { self.expected_identifier(); - Ident::default() + self.unknown_ident_at_previous_token_end() } }; @@ -272,7 +272,7 @@ fn empty_trait( location: Location, ) -> NoirTrait { NoirTrait { - name: Ident::default(), + name: Ident::new(String::new(), location), generics: Vec::new(), bounds: Vec::new(), where_clause: Vec::new(), diff --git a/compiler/noirc_frontend/src/parser/parser/type_alias.rs b/compiler/noirc_frontend/src/parser/parser/type_alias.rs index 7cf039e0947..0c9824046cd 100644 --- a/compiler/noirc_frontend/src/parser/parser/type_alias.rs +++ b/compiler/noirc_frontend/src/parser/parser/type_alias.rs @@ -1,7 +1,7 @@ use noirc_errors::Location; use crate::{ - ast::{Ident, ItemVisibility, NoirTypeAlias, UnresolvedType, UnresolvedTypeData}, + ast::{ItemVisibility, NoirTypeAlias, UnresolvedType, UnresolvedTypeData}, token::Token, }; @@ -19,7 +19,7 @@ impl Parser<'_> { let location = self.location_at_previous_token_end(); return NoirTypeAlias { visibility, - name: Ident::default(), + name: self.unknown_ident_at_previous_token_end(), generics: Vec::new(), typ: UnresolvedType { typ: UnresolvedTypeData::Error, location }, location: start_location, diff --git a/compiler/noirc_frontend/src/parser/parser/types.rs b/compiler/noirc_frontend/src/parser/parser/types.rs index b399441ad03..930b2652641 100644 --- a/compiler/noirc_frontend/src/parser/parser/types.rs +++ b/compiler/noirc_frontend/src/parser/parser/types.rs @@ -472,6 +472,7 @@ impl Parser<'_> { mod tests { use std::collections::BTreeMap; + use insta::assert_snapshot; use proptest::prelude::*; use strum::IntoEnumIterator; @@ -707,7 +708,7 @@ mod tests { let mut parser = Parser::for_str_with_dummy_file(&src); parser.parse_type(); let error = get_single_error(&parser.errors, span); - assert_eq!(error.to_string(), "Expected a ']' but found end of input"); + assert_snapshot!(error.to_string(), @"Expected a ']' but found end of input"); } #[test] diff --git a/compiler/noirc_frontend/src/parser/parser/use_tree.rs b/compiler/noirc_frontend/src/parser/parser/use_tree.rs index ebe05863211..2d16e90ca7e 100644 --- a/compiler/noirc_frontend/src/parser/parser/use_tree.rs +++ b/compiler/noirc_frontend/src/parser/parser/use_tree.rs @@ -111,7 +111,7 @@ impl Parser<'_> { } UseTree { prefix, - kind: UseTreeKind::Path(Ident::default(), None), + kind: UseTreeKind::Path(self.unknown_ident_at_previous_token_end(), None), location: self.location_since(start_location), } } else { diff --git a/test_programs/compile_failure/invalid_mod_mod_path/stderr.txt b/test_programs/compile_failure/invalid_mod_mod_path/stderr.txt index 9ce5c2b617d..741cd0b34e5 100644 --- a/test_programs/compile_failure/invalid_mod_mod_path/stderr.txt +++ b/test_programs/compile_failure/invalid_mod_mod_path/stderr.txt @@ -1,24 +1,3 @@ -error: Expected a 'fn' but found 'foo' - ┌─ src/mod.nr:1:5 - │ -1 │ pub foo() -> bool { - │ --- - │ - -error: Module '' is already part of the crate - ┌─ src/main.nr:1:1 - │ -1 │ mod crate::mod; - │ - - │ - -error: Note: was originally declared here - ┌─ src/main.nr:1:1 - │ -1 │ mod crate::mod; - │ - - │ - error: Expected an identifier but found 'crate' ┌─ src/main.nr:1:5 │ @@ -26,13 +5,6 @@ error: Expected an identifier but found 'crate' │ ----- │ -error: Expected an item but found 'crate' - ┌─ src/main.nr:1:5 - │ -1 │ mod crate::mod; - │ ----- - │ - error: Expected an item but found '::' ┌─ src/main.nr:1:10 │ @@ -47,11 +19,4 @@ error: Expected an identifier but found ';' │ - │ -error: Expected an item but found ';' - ┌─ src/main.nr:1:15 - │ -1 │ mod crate::mod; - │ - - │ - -Aborting due to 8 previous errors +Aborting due to 3 previous errors