frontend: provide contextual source repair advice
This commit is contained in:
1 parent
008867fe48
commit
2c6c7a3dcd
37 files changed
+562
-24
No files matched your search
+13
-1
@@ -150,6 +150,7 @@ pub const Problem = struct {
|
||||
span: Span,
|
||||
message: []const u8,
|
||||
fields: []const Field = &.{},
|
||||
repair_candidates: []const @import("../diag.zig").RepairCandidate = &.{},
|
||||
|
||||
pub const Field = struct { name: []const u8, value: []const u8 };
|
||||
};
|
||||
@@ -364,6 +365,17 @@ const Lowerer = struct {
|
||||
return error.Lower;
|
||||
}
|
||||
|
||||
fn invalidWidening(l: *Lowerer, span: Span, fields: []const Problem.Field) Error {
|
||||
l.problem = .{
|
||||
.code = "E7005",
|
||||
.span = span,
|
||||
.message = "`as` only widens without loss; use `as!` (checked, traps T0006 when the value does not fit) or `as%` (wrapping)",
|
||||
.fields = try l.arena.dupe(Problem.Field, fields),
|
||||
.repair_candidates = @import("../diag.zig").SourceRepairKind.one(.numeric_cast_modes),
|
||||
};
|
||||
return error.Lower;
|
||||
}
|
||||
|
||||
fn notYet(l: *Lowerer, span: Span, construct: []const u8) Error {
|
||||
l.unimpl = .{ .span = span, .construct = construct };
|
||||
return error.Unimplemented;
|
||||
@@ -1678,7 +1690,7 @@ const Lowerer = struct {
|
||||
const a = std.meta.stringToEnum(air_module.IntType, v.ty.int).?;
|
||||
const b = std.meta.stringToEnum(air_module.IntType, to.int).?;
|
||||
if (a != b and !verifier_types.lossless(a, b))
|
||||
return l.fail("E7005", e.span, "`as` only widens without loss; use `as!` (checked, traps T0006 when the value does not fit) or `as%` (wrapping)", &.{ .{ .name = "from", .value = v.ty.int }, .{ .name = "to", .value = to.int } });
|
||||
return l.invalidWidening(e.span, &.{ .{ .name = "from", .value = v.ty.int }, .{ .name = "to", .value = to.int } });
|
||||
}
|
||||
const mode = switch (x.mode) {
|
||||
.widen => "widen",
|
||||
|
||||
Reference in new issue
Block a user