mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Merge 964a3f51df into 53e615b920
This commit is contained in:
commit
33a6b4ac70
3 changed files with 23 additions and 2 deletions
|
|
@ -29142,7 +29142,7 @@ fn coerceExtra(
|
||||||
|
|
||||||
// E!T to T
|
// E!T to T
|
||||||
if (inst_ty.zigTypeTag(zcu) == .error_union and
|
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, "cannot convert error union to payload type", .{});
|
||||||
try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});
|
try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});
|
||||||
|
|
@ -29150,7 +29150,7 @@ fn coerceExtra(
|
||||||
|
|
||||||
// ?T to T
|
// ?T to T
|
||||||
if (inst_ty.zigTypeTag(zcu) == .optional and
|
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, "cannot convert optional to payload type", .{});
|
||||||
try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
|
try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
|
||||||
|
|
|
||||||
|
|
@ -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'
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
const x = 0;
|
||||||
|
const y: ?usize = null;
|
||||||
|
comptime {
|
||||||
|
x += y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// error
|
||||||
|
//
|
||||||
|
// :4:10: error: expected type 'comptime_int', found '?usize'
|
||||||
Loading…
Add table
Reference in a new issue