diff --git a/src/Sema.zig b/src/Sema.zig index 3361d1a59cea..cc54ba3a4727 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -29153,7 +29153,7 @@ fn coerceExtra( // E!T to T if (inst_ty.zigTypeTag(zcu) == .error_union and - (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src, maybe_inst_val)) == .ok) + (try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty.errorUnionPayload(zcu), false, target, dest_ty_src, inst_src, null)) == .ok) { try sema.errNote(inst_src, msg, "cannot convert error union to payload type", .{}); try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{}); @@ -29161,7 +29161,7 @@ fn coerceExtra( // ?T to T if (inst_ty.zigTypeTag(zcu) == .optional and - (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src, maybe_inst_val)) == .ok) + (try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty.optionalChild(zcu), false, target, dest_ty_src, inst_src, null)) == .ok) { try sema.errNote(inst_src, msg, "cannot convert optional to payload type", .{}); try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{}); diff --git a/test/cases/compile_errors/comptime_coercing_int_error_union_doesnt_crash.zig b/test/cases/compile_errors/comptime_coercing_int_error_union_doesnt_crash.zig new file mode 100644 index 000000000000..3ae81dae603a --- /dev/null +++ b/test/cases/compile_errors/comptime_coercing_int_error_union_doesnt_crash.zig @@ -0,0 +1,12 @@ +const x = 0; +comptime { + x += foo(); +} + +fn foo() !usize { + return 0; +} + +// error +// +// :3:13: error: expected type 'comptime_int', found 'error{}!usize' diff --git a/test/cases/compile_errors/comptime_coercing_int_optional_doesnt_crash.zig b/test/cases/compile_errors/comptime_coercing_int_optional_doesnt_crash.zig new file mode 100644 index 000000000000..819d92943b4d --- /dev/null +++ b/test/cases/compile_errors/comptime_coercing_int_optional_doesnt_crash.zig @@ -0,0 +1,9 @@ +const x = 0; +const y: ?usize = null; +comptime { + x += y; +} + +// error +// +// :4:10: error: expected type 'comptime_int', found '?usize'