File tree 2 files changed +37
-2
lines changed
compiler/noirc_frontend/src
2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -1099,13 +1099,19 @@ impl Type {
1099
1099
| Type :: Unit
1100
1100
| Type :: Constant ( _)
1101
1101
| Type :: Slice ( _)
1102
- | Type :: TypeVariable ( _, _)
1103
- | Type :: NamedGeneric ( _, _, _)
1104
1102
| Type :: Function ( _, _, _, _)
1105
1103
| Type :: FmtString ( _, _)
1106
1104
| Type :: InfixExpr ( ..)
1107
1105
| Type :: Error => true ,
1108
1106
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
+
1109
1115
// Quoted objects only exist at compile-time where the only execution
1110
1116
// environment is the interpreter. In this environment, they are valid.
1111
1117
Type :: Quoted ( _) => true ,
Original file line number Diff line number Diff line change @@ -3424,3 +3424,32 @@ fn errors_on_unused_function() {
3424
3424
assert_eq ! ( ident. to_string( ) , "foo" ) ;
3425
3425
assert_eq ! ( * item_type, "function" ) ;
3426
3426
}
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
+ }
You can’t perform that action at this time.
0 commit comments