stage 1: improve error message if error union is cast to payload (#10770)

Also: Added special error message for for `?T` to `T` casting
This commit is contained in:
Sebsatian Keller
2022-02-10 02:35:53 +01:00
committed by GitHub
parent 1e5a494603
commit f5471299d8
2 changed files with 35 additions and 7 deletions
+7 -7
View File
@@ -790,9 +790,9 @@ pub fn addCases(ctx: *TestContext) !void {
"tmp.zig:1:17: note: function cannot return an error",
"tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set'",
"tmp.zig:7:17: note: function cannot return an error",
"tmp.zig:11:15: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'",
"tmp.zig:11:15: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'",
"tmp.zig:10:17: note: function cannot return an error",
"tmp.zig:15:14: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'",
"tmp.zig:15:14: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'",
"tmp.zig:14:5: note: cannot store an error in type 'u32'",
});
@@ -1879,7 +1879,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ _ = afoo;
\\}
, &[_][]const u8{
"tmp.zig:12:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'",
"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'",
});
ctx.objErrStage1("assigning to struct or union fields that are not optionals with a function that returns an optional",
@@ -1899,7 +1899,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ _ = s;
\\}
, &[_][]const u8{
"tmp.zig:11:27: error: expected type 'u8', found '?u8'",
"tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'",
});
ctx.objErrStage1("missing result type for phi node",
@@ -2308,7 +2308,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ not_optional: i32,
\\};
, &[_][]const u8{
"tmp.zig:3:36: error: expected type 'i32', found '?i32'",
"tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'",
});
ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr",
@@ -2325,7 +2325,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ not_optional: i32,
\\};
, &[_][]const u8{
"tmp.zig:3:36: error: expected type 'i32', found '?i32'",
"tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'",
});
ctx.objErrStage1("const frame cast to anyframe",
@@ -8828,7 +8828,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ v = u;
\\}
, &[_][]const u8{
"tmp.zig:4:9: error: expected type '*anyopaque', found '?*anyopaque'",
"tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'",
});
ctx.objErrStage1("Issue #6823: don't allow .* to be followed by **",