Skip to content

Commit

Permalink
chore: use push_err more in elaborator (#5336)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

Quick PR to make more use of the `push_err` helper when creating errors
in the elaborator.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jun 26, 2024
1 parent c44e2b9 commit c7dcda4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
18 changes: 6 additions & 12 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,11 @@ impl<'context> Elaborator<'context> {
self.resolve_type(typ.clone())
};
if !matches!(typ, Type::FieldElement | Type::Integer(_, _)) {
let unsupported_typ_err =
CompilationError::ResolverError(ResolverError::UnsupportedNumericGenericType {
ident: ident.clone(),
typ: typ.clone(),
});
self.errors.push((unsupported_typ_err, self.file));
let unsupported_typ_err = ResolverError::UnsupportedNumericGenericType {
ident: ident.clone(),
typ: typ.clone(),
};
self.push_err(unsupported_typ_err);
}
Kind::Numeric(Box::new(typ))
} else {
Expand Down Expand Up @@ -788,12 +787,7 @@ impl<'context> Elaborator<'context> {
let definition = DefinitionKind::GenericType(type_variable);
self.add_variable_decl_inner(ident.clone(), false, false, false, definition);

self.errors.push((
CompilationError::ResolverError(ResolverError::UseExplicitNumericGeneric {
ident,
}),
self.file,
));
self.push_err(ResolverError::UseExplicitNumericGeneric { ident });
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions compiler/noirc_frontend/src/elaborator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
},
hir::{
comptime::{Interpreter, Value},
def_collector::dc_crate::CompilationError,
def_map::ModuleDefId,
resolution::{
errors::ResolverError,
Expand Down Expand Up @@ -170,12 +169,11 @@ impl<'context> Elaborator<'context> {
// }
if let Type::NamedGeneric(_, name, resolved_kind) = &resolved_type {
if matches!(resolved_kind, Kind::Numeric { .. }) && matches!(kind, Kind::Normal) {
let expected_typ_err =
CompilationError::ResolverError(ResolverError::NumericGenericUsedForType {
name: name.to_string(),
span: span.expect("Type should have span"),
});
self.errors.push((expected_typ_err, self.file));
let expected_typ_err = ResolverError::NumericGenericUsedForType {
name: name.to_string(),
span: span.expect("Type should have span"),
};
self.push_err(expected_typ_err);
return Type::Error;
}
}
Expand Down

0 comments on commit c7dcda4

Please sign in to comment.