Skip to content

Commit 9845edc

Browse files
authored
fix(parser): avoid using Location::dummy() (#8178)
1 parent e1ec3d9 commit 9845edc

6 files changed

Lines changed: 25 additions & 23 deletions

File tree

compiler/noirc_frontend/src/parser/parser/function.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ impl Parser<'_> {
223223
);
224224

225225
let visibility = Visibility::Private;
226-
let typ =
227-
UnresolvedType { typ: UnresolvedTypeData::Error, location: Location::dummy() };
226+
let location = self.location_at_previous_token_end();
227+
let typ = UnresolvedType { typ: UnresolvedTypeData::Error, location };
228228
(visibility, typ)
229229
} else {
230230
(
@@ -328,7 +328,7 @@ fn empty_function(location: Location) -> FunctionDefinitionWithOptionalBody {
328328
body: None,
329329
location: Location::new(span, location.file),
330330
where_clause: Vec::new(),
331-
return_type: FunctionReturnType::Default(Location::dummy()),
331+
return_type: FunctionReturnType::Default(Location::new(span, location.file)),
332332
return_visibility: Visibility::Private,
333333
}
334334
}

compiler/noirc_frontend/src/parser/parser/global.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ impl Parser<'_> {
2727

2828
let Some(ident) = self.eat_ident() else {
2929
self.eat_semicolon();
30+
let location = self.location_at_previous_token_end();
3031
return LetStatement {
3132
pattern: ident_to_pattern(Ident::default(), mutable),
32-
r#type: UnresolvedType {
33-
typ: UnresolvedTypeData::Unspecified,
34-
location: Location::dummy(),
35-
},
36-
expression: Expression { kind: ExpressionKind::Error, location: Location::dummy() },
33+
r#type: UnresolvedType { typ: UnresolvedTypeData::Unspecified, location },
34+
expression: Expression { kind: ExpressionKind::Error, location },
3735
attributes,
3836
comptime,
3937
is_global_let,
@@ -48,7 +46,8 @@ impl Parser<'_> {
4846
self.parse_expression_or_error()
4947
} else {
5048
self.push_error(ParserErrorReason::GlobalWithoutValue, pattern.location());
51-
Expression { kind: ExpressionKind::Error, location: Location::dummy() }
49+
let location = self.location_at_previous_token_end();
50+
Expression { kind: ExpressionKind::Error, location }
5251
};
5352

5453
self.eat_semicolon_or_error();

compiler/noirc_frontend/src/parser/parser/impls.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,18 @@ impl Parser<'_> {
155155
let Some(name) = self.eat_ident() else {
156156
self.expected_identifier();
157157
self.eat_semicolons();
158+
let location = self.location_at_previous_token_end();
158159
return Some(TraitImplItemKind::Type {
159160
name: Ident::default(),
160-
alias: UnresolvedType {
161-
typ: UnresolvedTypeData::Error,
162-
location: Location::dummy(),
163-
},
161+
alias: UnresolvedType { typ: UnresolvedTypeData::Error, location },
164162
});
165163
};
166164

167165
let alias = if self.eat_assign() {
168166
self.parse_type_or_error()
169167
} else {
170-
UnresolvedType { typ: UnresolvedTypeData::Error, location: Location::dummy() }
168+
let location = self.location_at_previous_token_end();
169+
UnresolvedType { typ: UnresolvedTypeData::Error, location }
171170
};
172171

173172
self.eat_semicolon_or_error();
@@ -195,7 +194,8 @@ impl Parser<'_> {
195194
self.parse_expression_or_error()
196195
} else {
197196
self.expected_token(Token::Assign);
198-
Expression { kind: ExpressionKind::Error, location: Location::dummy() }
197+
let location = self.location_at_previous_token_end();
198+
Expression { kind: ExpressionKind::Error, location }
199199
};
200200

201201
self.eat_semicolon_or_error();

compiler/noirc_frontend/src/parser/parser/statement.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,11 @@ impl Parser<'_> {
365365
}
366366

367367
fn empty_for_loop(&mut self, identifier: Ident, start_location: Location) -> ForLoopStatement {
368+
let location = self.location_at_previous_token_end();
368369
ForLoopStatement {
369370
identifier,
370-
range: ForRange::Array(Expression {
371-
kind: ExpressionKind::Error,
372-
location: Location::dummy(),
373-
}),
374-
block: Expression { kind: ExpressionKind::Error, location: Location::dummy() },
371+
range: ForRange::Array(Expression { kind: ExpressionKind::Error, location }),
372+
block: Expression { kind: ExpressionKind::Error, location },
375373
location: self.location_since(start_location),
376374
}
377375
}

compiler/noirc_frontend/src/parser/parser/traits.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ impl Parser<'_> {
204204
self.parse_type_or_error()
205205
} else {
206206
self.expected_token(Token::Colon);
207-
UnresolvedType { typ: UnresolvedTypeData::Unspecified, location: Location::dummy() }
207+
let location = self.location_at_previous_token_end();
208+
UnresolvedType { typ: UnresolvedTypeData::Unspecified, location }
208209
};
209210

210211
let default_value =

compiler/noirc_frontend/src/parser/parser/type_alias.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ impl Parser<'_> {
1616
) -> NoirTypeAlias {
1717
let Some(name) = self.eat_ident() else {
1818
self.expected_identifier();
19+
let location = self.location_at_previous_token_end();
1920
return NoirTypeAlias {
2021
visibility,
2122
name: Ident::default(),
2223
generics: Vec::new(),
23-
typ: UnresolvedType { typ: UnresolvedTypeData::Error, location: Location::dummy() },
24+
typ: UnresolvedType { typ: UnresolvedTypeData::Error, location },
2425
location: start_location,
2526
};
2627
};
@@ -37,7 +38,10 @@ impl Parser<'_> {
3738
visibility,
3839
name,
3940
generics,
40-
typ: UnresolvedType { typ: UnresolvedTypeData::Error, location: Location::dummy() },
41+
typ: UnresolvedType {
42+
typ: UnresolvedTypeData::Error,
43+
location: self.location_at_previous_token_end(),
44+
},
4145
location,
4246
};
4347
}

0 commit comments

Comments
 (0)