| author | |
| committer | |
| log | e9eee8dace5af05f0c47f29443542783ed5fa080 |
| tree | ab44521cae34e65c3ee166a9e5bc2248246cba47 |
| parent | e395c24c6dc4b8ad7688c1ad7754697166551bcb |
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>4 files changed, 33 insertions(+), 8 deletions(-)
src/Type.zig+16-2| ... | @@ -254,9 +254,23 @@ pub fn print(ty: Type, writer: *std.io.Writer, pt: Zcu.PerThread) std.io.Writer. | ... | @@ -254,9 +254,23 @@ pub fn print(ty: Type, writer: *std.io.Writer, pt: Zcu.PerThread) std.io.Writer. |
| 254 | }); | 254 | }); |
| 255 | }, | 255 | }, |
| 256 | .error_set_type => |error_set_type| { | 256 | .error_set_type => |error_set_type| { |
| 257 | const names = error_set_type.names; | 257 | const NullTerminatedString = InternPool.NullTerminatedString; |
| 258 | const sorted_names = zcu.gpa.dupe(NullTerminatedString, error_set_type.names.get(ip)) catch { | ||
| 259 | zcu.comp.setAllocFailure(); | ||
| 260 | return writer.writeAll("error{...}"); | ||
| 261 | }; | ||
| 262 | defer zcu.gpa.free(sorted_names); | ||
| 263 | |||
| 264 | std.mem.sortUnstable(NullTerminatedString, sorted_names, ip, struct { | ||
| 265 | fn lessThan(ip_: *InternPool, lhs: NullTerminatedString, rhs: NullTerminatedString) bool { | ||
| 266 | const lhs_slice = lhs.toSlice(ip_); | ||
| 267 | const rhs_slice = rhs.toSlice(ip_); | ||
| 268 | return std.mem.lessThan(u8, lhs_slice, rhs_slice); | ||
| 269 | } | ||
| 270 | }.lessThan); | ||
| 271 | |||
| 258 | try writer.writeAll("error{"); | 272 | try writer.writeAll("error{"); |
| 259 | for (names.get(ip), 0..) |name, i| { | 273 | for (sorted_names, 0..) |name, i| { |
| 260 | if (i != 0) try writer.writeByte(','); | 274 | if (i != 0) try writer.writeByte(','); |
| 261 | try writer.print("{f}", .{name.fmt(ip)}); | 275 | try writer.print("{f}", .{name.fmt(ip)}); |
| 262 | } | 276 | } |
test/cases/compile_errors/error_set_display.zig created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | const Set0 = error{ A, B, C, D, E, F }; | ||
| 2 | const Set1 = error{ F, E, D, C, A }; | ||
| 3 | comptime { | ||
| 4 | const x = Set0.B; | ||
| 5 | const y: Set1 = @errorCast(x); | ||
| 6 | _ = y; | ||
| 7 | } | ||
| 8 | |||
| 9 | // error | ||
| 10 | // | ||
| 11 | // :5:21: error: 'error.B' not a member of error set 'error{A,C,D,E,F}' | ||
test/cases/compile_errors/invalid_pointer_coercions.zig+2-2| ... | @@ -54,8 +54,8 @@ export fn ptr_to_underaligned_ptr() void { | ... | @@ -54,8 +54,8 @@ export fn ptr_to_underaligned_ptr() void { |
| 54 | 54 | ||
| 55 | // error | 55 | // error |
| 56 | // | 56 | // |
| 57 | // :16:33: error: expected type '*error{Foo,Bar}', found '*error{Foo}' | 57 | // :16:33: error: expected type '*error{Bar,Foo}', found '*error{Foo}' |
| 58 | // :16:33: note: pointer type child 'error{Foo}' cannot cast into pointer type child 'error{Foo,Bar}' | 58 | // :16:33: note: pointer type child 'error{Foo}' cannot cast into pointer type child 'error{Bar,Foo}' |
| 59 | // :16:33: note: 'error.Bar' not a member of destination error set | 59 | // :16:33: note: 'error.Bar' not a member of destination error set |
| 60 | // :22:24: error: expected type '*anyerror', found '*error{Foo}' | 60 | // :22:24: error: expected type '*anyerror', found '*error{Foo}' |
| 61 | // :22:24: note: pointer type child 'error{Foo}' cannot cast into pointer type child 'anyerror' | 61 | // :22:24: note: pointer type child 'error{Foo}' cannot cast into pointer type child 'anyerror' |
test/src/Debugger.zig+4-4| ... | @@ -491,16 +491,16 @@ pub fn addTestsForTarget(db: *Debugger, target: *const Target) void { | ... | @@ -491,16 +491,16 @@ pub fn addTestsForTarget(db: *Debugger, target: *const Target) void { |
| 491 | \\ (error{One,Two}) Two = error.Two | 491 | \\ (error{One,Two}) Two = error.Two |
| 492 | \\ } | 492 | \\ } |
| 493 | \\ (type) Three = error { | 493 | \\ (type) Three = error { |
| 494 | \\ (error{One,Two,Three}) One = error.One | 494 | \\ (error{One,Three,Two}) One = error.One |
| 495 | \\ (error{One,Two,Three}) Two = error.Two | 495 | \\ (error{One,Three,Two}) Two = error.Two |
| 496 | \\ (error{One,Two,Three}) Three = error.Three | 496 | \\ (error{One,Three,Two}) Three = error.Three |
| 497 | \\ } | 497 | \\ } |
| 498 | \\} | 498 | \\} |
| 499 | \\(lldb) frame variable --show-types -- errors | 499 | \\(lldb) frame variable --show-types -- errors |
| 500 | \\(root.errors.Errors) errors = { | 500 | \\(root.errors.Errors) errors = { |
| 501 | \\ (error{One}) .one = error.One | 501 | \\ (error{One}) .one = error.One |
| 502 | \\ (error{One,Two}) .two = error.Two | 502 | \\ (error{One,Two}) .two = error.Two |
| 503 | \\ (error{One,Two,Three}) .three = error.Three | 503 | \\ (error{One,Three,Two}) .three = error.Three |
| 504 | \\ (anyerror) .any = error.Any | 504 | \\ (anyerror) .any = error.Any |
| 505 | \\ (anyerror!void) .any_void = { | 505 | \\ (anyerror!void) .any_void = { |
| 506 | \\ (anyerror) .error = error.NotVoid | 506 | \\ (anyerror) .error = error.NotVoid |