Commit 3e084d8de3

Veikka Tuominen <git@vexu.eu>
2023-01-05 12:43:06
Sema: only untyped undefined should coerce to all types
Closes #13958
1 parent 01dba1c
Changed files (2)
src/Sema.zig
@@ -24477,7 +24477,7 @@ fn coerceExtra(
         return block.addBitCast(dest_ty, inst);
     }
 
-    const is_undef = if (maybe_inst_val) |val| val.isUndef() else false;
+    const is_undef = inst_ty.zigTypeTag() == .Undefined;
 
     switch (dest_ty.zigTypeTag()) {
         .Optional => optional: {
test/cases/compile_errors/only_untyped_undef_coerces_to_all_types.zig
@@ -0,0 +1,11 @@
+pub export fn entry() void {
+    const x: []u8 = undefined;
+    const y: f32 = x;
+    _ = y;
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :3:20: error: expected type 'f32', found '[]u8'