Skip to content

Commit

Permalink
update UnspecifiedGlobalType error message, annotate types in depende…
Browse files Browse the repository at this point in the history
…ncy cycle test
  • Loading branch information
michaeljklein committed Nov 22, 2024
1 parent dd9bd09 commit 33b4597
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
6 changes: 3 additions & 3 deletions compiler/noirc_frontend/src/hir/resolution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub enum ResolverError {
JumpOutsideLoop { is_break: bool, span: Span },
#[error("Only `comptime` globals can be mutable")]
MutableGlobal { span: Span },
#[error("Globals must have a specified type (RHS inferred to have type `{expected_type}`)")]
#[error("Globals must have a specified type")]
UnspecifiedGlobalType { span: Span, expected_type: Type },
#[error("Self-referential structs are not supported")]
SelfReferentialStruct { span: Span },
Expand Down Expand Up @@ -435,8 +435,8 @@ impl<'a> From<&'a ResolverError> for Diagnostic {
},
ResolverError::UnspecifiedGlobalType { span, expected_type } => {
Diagnostic::simple_error(
format!("Globals must have a specified type (RHS inferred to have type `{expected_type}`)"),
String::new(),
"Globals must have a specified type".to_string(),
format!("Inferred type is `{expected_type}`"),
*span,
)
},
Expand Down
14 changes: 3 additions & 11 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,23 +1300,15 @@ fn lambda$f1(mut env$l1: (Field)) -> Field {
#[test]
fn deny_cyclic_globals() {
let src = r#"
global A = B;
global B = A;
global A: u32 = B;
global B: u32 = A;
fn main() {}
"#;

let errors = get_program_errors(src);
assert_eq!(errors.len(), 3);
assert_eq!(errors.len(), 1);
assert!(matches!(
errors[0].0,
CompilationError::ResolverError(ResolverError::UnspecifiedGlobalType { .. })
));
assert!(matches!(
errors[1].0,
CompilationError::ResolverError(ResolverError::UnspecifiedGlobalType { .. })
));
assert!(matches!(
errors[2].0,
CompilationError::ResolverError(ResolverError::DependencyCycle { .. })
));
}
Expand Down

0 comments on commit 33b4597

Please sign in to comment.