Sema: add "cannot convert to payload type" error notes

This commit is contained in:
Veikka Tuominen
2022-07-11 14:17:22 +03:00
parent 2a41b1449b
commit c9e1360cdb
10 changed files with 75 additions and 26 deletions

View File

@@ -15,7 +15,9 @@ export fn entry() void {
}
// error
// backend=stage1
// backend=stage2
// target=native
//
// tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'
// :11:27: error: expected type 'u8', found '?u8'
// :11:27: note: cannot convert optional to payload type
// :11:27: note: consider using `.?`, `orelse`, or `if`

View File

@@ -9,4 +9,5 @@ fn foo() !void {
// backend=stage2
// target=native
//
// :2:12: error: error is discarded. consider using `try`, `catch`, or `if`
// :2:12: error: error is discarded
// :2:12: note: consider using `try`, `catch`, or `if`

View File

@@ -7,4 +7,5 @@ fn bar() anyerror!i32 { return 0; }
// backend=stage2
// target=native
//
// :2:14: error: error is ignored. consider using `try`, `catch`, or `if`
// :2:14: error: error is ignored
// :2:14: note: consider using `try`, `catch`, or `if`

View File

@@ -17,6 +17,9 @@ fn bad() anyerror!void {
// backend=stage2
// target=native
//
// :2:24: error: error is ignored. consider using `try`, `catch`, or `if`
// :6:25: error: error is ignored. consider using `try`, `catch`, or `if`
// :10:25: error: error is ignored. consider using `try`, `catch`, or `if`
// :2:24: error: error is ignored
// :2:24: note: consider using `try`, `catch`, or `if`
// :6:25: error: error is ignored
// :6:25: note: consider using `try`, `catch`, or `if`
// :10:25: error: error is ignored
// :10:25: note: consider using `try`, `catch`, or `if`

View File

@@ -0,0 +1,14 @@
export fn foo() void {
var u: ?*anyopaque = null;
var v: *anyopaque = undefined;
v = u;
}
// error
// backend=stage2
// target=native
//
// :4:9: error: expected type '*anyopaque', found '?*anyopaque'
// :4:9: note: cannot convert optional to payload type
// :4:9: note: consider using `.?`, `orelse`, or `if`
// :4:9: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque'

View File

@@ -15,7 +15,9 @@ export fn entry() void {
}
// error
// backend=stage1
// backend=stage2
// target=native
//
// tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'
// :12:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(tmp.get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'
// :12:25: note: cannot convert error union to payload type
// :12:25: note: consider using `try`, `catch`, or `if`

View File

@@ -12,7 +12,9 @@ pub const Container = struct {
};
// error
// backend=stage1
// backend=stage2
// target=native
//
// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
// :3:36: error: expected type 'i32', found '?i32'
// :3:36: note: cannot convert optional to payload type
// :3:36: note: consider using `.?`, `orelse`, or `if`

View File

@@ -12,7 +12,9 @@ pub const Container = struct {
};
// error
// backend=stage1
// backend=stage2
// target=native
//
// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
// :3:36: error: expected type 'i32', found '?i32'
// :3:36: note: cannot convert optional to payload type
// :3:36: note: consider using `.?`, `orelse`, or `if`

View File

@@ -1,11 +0,0 @@
export fn foo() void {
var u: ?*anyopaque = null;
var v: *anyopaque = undefined;
v = u;
}
// error
// backend=stage1
// target=native
//
// tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'