| ... | @@ -1179,6 +1179,18 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T | ... | @@ -1179,6 +1179,18 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T |
| 1179 | return sema.fail(block, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty }); | 1179 | return sema.fail(block, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty }); |
| 1180 | } | 1180 | } |
| 1181 | | 1181 | |
| | 1182 | fn failWithErrorSetCodeMissing( |
| | 1183 | sema: *Sema, |
| | 1184 | block: *Block, |
| | 1185 | src: LazySrcLoc, |
| | 1186 | dest_err_set_ty: Type, |
| | 1187 | src_err_set_ty: Type, |
| | 1188 | ) CompileError { |
| | 1189 | return sema.fail(block, src, "expected type '{}', found type '{}'", .{ |
| | 1190 | dest_err_set_ty, src_err_set_ty, |
| | 1191 | }); |
| | 1192 | } |
| | 1193 | |
| 1182 | /// We don't return a pointer to the new error note because the pointer | 1194 | /// We don't return a pointer to the new error note because the pointer |
| 1183 | /// becomes invalid when you add another one. | 1195 | /// becomes invalid when you add another one. |
| 1184 | fn errNote( | 1196 | fn errNote( |
| ... | @@ -12858,47 +12870,30 @@ fn wrapErrorUnion( | ... | @@ -12858,47 +12870,30 @@ fn wrapErrorUnion( |
| 12858 | } | 12870 | } |
| 12859 | switch (dest_err_set_ty.tag()) { | 12871 | switch (dest_err_set_ty.tag()) { |
| 12860 | .anyerror => {}, | 12872 | .anyerror => {}, |
| 12861 | .error_set_single => { | 12873 | .error_set_single => ok: { |
| 12862 | const expected_name = val.castTag(.@"error").?.data.name; | 12874 | const expected_name = val.castTag(.@"error").?.data.name; |
| 12863 | const n = dest_err_set_ty.castTag(.error_set_single).?.data; | 12875 | const n = dest_err_set_ty.castTag(.error_set_single).?.data; |
| 12864 | if (!mem.eql(u8, expected_name, n)) { | 12876 | if (mem.eql(u8, expected_name, n)) break :ok; |
| 12865 | return sema.fail( | 12877 | return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty); |
| 12866 | block, | | |
| 12867 | inst_src, | | |
| 12868 | "expected type '{}', found type '{}'", | | |
| 12869 | .{ dest_err_set_ty, inst_ty }, | | |
| 12870 | ); | | |
| 12871 | } | | |
| 12872 | }, | 12878 | }, |
| 12873 | .error_set => { | 12879 | .error_set => ok: { |
| 12874 | const expected_name = val.castTag(.@"error").?.data.name; | 12880 | const expected_name = val.castTag(.@"error").?.data.name; |
| 12875 | const error_set = dest_err_set_ty.castTag(.error_set).?.data; | 12881 | const error_set = dest_err_set_ty.castTag(.error_set).?.data; |
| 12876 | const names = error_set.names_ptr[0..error_set.names_len]; | 12882 | const names = error_set.names_ptr[0..error_set.names_len]; |
| 12877 | // TODO this is O(N). I'm putting off solving this until we solve inferred | 12883 | // TODO this is O(N). I'm putting off solving this until we solve inferred |
| 12878 | // error sets at the same time. | 12884 | // error sets at the same time. |
| 12879 | const found = for (names) |name| { | 12885 | for (names) |name| { |
| 12880 | if (mem.eql(u8, expected_name, name)) break true; | 12886 | if (mem.eql(u8, expected_name, name)) break :ok; |
| 12881 | } else false; | | |
| 12882 | if (!found) { | | |
| 12883 | return sema.fail( | | |
| 12884 | block, | | |
| 12885 | inst_src, | | |
| 12886 | "expected type '{}', found type '{}'", | | |
| 12887 | .{ dest_err_set_ty, inst_ty }, | | |
| 12888 | ); | | |
| 12889 | } | 12887 | } |
| | 12888 | return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty); |
| 12890 | }, | 12889 | }, |
| 12891 | .error_set_inferred => { | 12890 | .error_set_inferred => ok: { |
| | 12891 | const err_set_payload = dest_err_set_ty.castTag(.error_set_inferred).?.data; |
| | 12892 | if (err_set_payload.is_anyerror) break :ok; |
| 12892 | const expected_name = val.castTag(.@"error").?.data.name; | 12893 | const expected_name = val.castTag(.@"error").?.data.name; |
| 12893 | const map = &dest_err_set_ty.castTag(.error_set_inferred).?.data.map; | 12894 | if (err_set_payload.map.contains(expected_name)) break :ok; |
| 12894 | if (!map.contains(expected_name)) { | 12895 | // TODO error set resolution here before emitting a compile error |
| 12895 | return sema.fail( | 12896 | return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty); |
| 12896 | block, | | |
| 12897 | inst_src, | | |
| 12898 | "expected type '{}', found type '{}'", | | |
| 12899 | .{ dest_err_set_ty, inst_ty }, | | |
| 12900 | ); | | |
| 12901 | } | | |
| 12902 | }, | 12897 | }, |
| 12903 | else => unreachable, | 12898 | else => unreachable, |
| 12904 | } | 12899 | } |