Skip to content

Commit c3b5fb2

Browse files
authored
Merge 8c7d3d2 into 344dd5e
2 parents 344dd5e + 8c7d3d2 commit c3b5fb2

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

compiler/noirc_frontend/src/hir_def/types.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1099,13 +1099,19 @@ impl Type {
10991099
| Type::Unit
11001100
| Type::Constant(_)
11011101
| Type::Slice(_)
1102-
| Type::TypeVariable(_, _)
1103-
| Type::NamedGeneric(_, _, _)
11041102
| Type::Function(_, _, _, _)
11051103
| Type::FmtString(_, _)
11061104
| Type::InfixExpr(..)
11071105
| Type::Error => true,
11081106

1107+
Type::TypeVariable(type_var, _) | Type::NamedGeneric(type_var, _, _) => {
1108+
if let TypeBinding::Bound(typ) = &*type_var.borrow() {
1109+
typ.is_valid_for_unconstrained_boundary()
1110+
} else {
1111+
true
1112+
}
1113+
}
1114+
11091115
// Quoted objects only exist at compile-time where the only execution
11101116
// environment is the interpreter. In this environment, they are valid.
11111117
Type::Quoted(_) => true,

compiler/noirc_frontend/src/tests.rs

+29
Original file line numberDiff line numberDiff line change
@@ -3424,3 +3424,32 @@ fn errors_on_unused_function() {
34243424
assert_eq!(ident.to_string(), "foo");
34253425
assert_eq!(*item_type, "function");
34263426
}
3427+
3428+
#[test]
3429+
fn constrained_reference_to_unconstrained() {
3430+
let src = r#"
3431+
fn main(mut x: u32, y: pub u32) {
3432+
let x_ref = &mut x;
3433+
if x == 5 {
3434+
unsafe {
3435+
mut_ref_input(x_ref, y);
3436+
}
3437+
}
3438+
3439+
assert(x == 10);
3440+
}
3441+
3442+
unconstrained fn mut_ref_input(x: &mut u32, y: u32) {
3443+
*x = y;
3444+
}
3445+
"#;
3446+
3447+
let errors = get_program_errors(src);
3448+
assert_eq!(errors.len(), 1);
3449+
3450+
let CompilationError::TypeError(TypeCheckError::ConstrainedReferenceToUnconstrained { .. }) =
3451+
&errors[0].0
3452+
else {
3453+
panic!("Expected an error about passing a constrained reference to unconstrained");
3454+
};
3455+
}

0 commit comments

Comments
 (0)