chore: no more loose numbers for location offsets

This commit is contained in:
rvcas 2023-02-09 09:16:54 -05:00
parent b803332f99
commit 461aaf14bd
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
3 changed files with 14 additions and 5 deletions

View File

@ -777,6 +777,13 @@ impl AssignmentKind {
pub fn is_expect(&self) -> bool { pub fn is_expect(&self) -> bool {
matches!(self, AssignmentKind::Expect) matches!(self, AssignmentKind::Expect)
} }
pub fn location_offset(&self) -> usize {
match self {
AssignmentKind::Let => 3,
AssignmentKind::Expect => 6,
}
}
} }
pub type MultiPattern<PatternConstructor, Type> = Vec<Pattern<PatternConstructor, Type>>; pub type MultiPattern<PatternConstructor, Type> = Vec<Pattern<PatternConstructor, Type>>;

View File

@ -906,7 +906,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
.push(Warning::SingleConstructorExpect { .push(Warning::SingleConstructorExpect {
location: Span { location: Span {
start: location.start, start: location.start,
end: location.start + 6, end: kind.location_offset(),
}, },
pattern_location: dbg!(untyped_pattern.location()), pattern_location: dbg!(untyped_pattern.location()),
value_location: dbg!(untyped_value.location()), value_location: dbg!(untyped_value.location()),

View File

@ -20,6 +20,8 @@ use super::{
TypeInfo, ValueConstructor, ValueConstructorVariant, TypeInfo, ValueConstructor, ValueConstructorVariant,
}; };
const PUB_OFFSET: usize = 3;
impl UntypedModule { impl UntypedModule {
pub fn infer( pub fn infer(
mut self, mut self,
@ -162,7 +164,7 @@ fn infer_definition(
environment.warnings.push(Warning::PubInValidatorModule { environment.warnings.push(Warning::PubInValidatorModule {
location: Span { location: Span {
start: location.start, start: location.start,
end: location.start + 3, end: location.start + PUB_OFFSET,
}, },
}) })
} }
@ -270,7 +272,7 @@ fn infer_definition(
environment.warnings.push(Warning::PubInValidatorModule { environment.warnings.push(Warning::PubInValidatorModule {
location: Span { location: Span {
start: location.start, start: location.start,
end: location.start + 3, end: location.start + PUB_OFFSET,
}, },
}) })
} }
@ -306,7 +308,7 @@ fn infer_definition(
environment.warnings.push(Warning::PubInValidatorModule { environment.warnings.push(Warning::PubInValidatorModule {
location: Span { location: Span {
start: location.start, start: location.start,
end: location.start + 3, end: location.start + PUB_OFFSET,
}, },
}) })
} }
@ -449,7 +451,7 @@ fn infer_definition(
environment.warnings.push(Warning::PubInValidatorModule { environment.warnings.push(Warning::PubInValidatorModule {
location: Span { location: Span {
start: location.start, start: location.start,
end: location.start + 3, end: location.start + PUB_OFFSET,
}, },
}) })
} }