Skip to content

Commit 9701324

Browse files
committed
Improve incompatible-units error message
1 parent 780780e commit 9701324

File tree

3 files changed

+89
-10
lines changed

3 files changed

+89
-10
lines changed

src/arr/trove/error.arr

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,15 +2475,94 @@ data RuntimeError:
24752475
end
24762476
| incompatible-units(op-name, l, r) with:
24772477
method render-fancy-reason(self, maybe-stack-loc, src-available, maybe-ast):
2478-
self.render-reason()
2478+
[ED.error:
2479+
cases(O.Option) maybe-stack-loc(0, false):
2480+
| some(loc) =>
2481+
if loc.is-builtin():
2482+
[ED.sequence:
2483+
ed-intro(self.op-name + " operation", loc, -1, true),
2484+
[ED.para:
2485+
ED.text("The left side had the unit: "),
2486+
ED.code(ED.text(self.l))],
2487+
[ED.para:
2488+
ED.text("The right side had the unit: "),
2489+
ED.code(ED.text(self.r))],
2490+
[ED.para: ED.text("These units are not compatible")],
2491+
please-report-bug()]
2492+
else if src-available(loc):
2493+
cases(O.Option) maybe-ast(loc):
2494+
| some(ast) =>
2495+
left-loc = ast.left.l
2496+
right-loc = ast.right.l
2497+
[ED.sequence:
2498+
ed-intro(self.op-name + " operation", loc, -1, true),
2499+
ED.cmcode(loc),
2500+
[ED.para:
2501+
ED.text("The "),
2502+
ED.highlight(ED.text("left side"), [ED.locs: left-loc], 0),
2503+
ED.text(" had the unit:")],
2504+
ED.code(ED.text(self.l)),
2505+
[ED.para:
2506+
ED.text("The "),
2507+
ED.highlight(ED.text("right side"), [ED.locs: right-loc], 1),
2508+
ED.text(" had the unit: ")],
2509+
ED.code(ED.text(self.r)),
2510+
[ED.para: ED.text("These units are not compatible")]]
2511+
| none => ED.text("TODO")
2512+
end
2513+
else:
2514+
[ED.sequence:
2515+
ed-intro(self.op-name + " operation", loc, -1, true),
2516+
ED.cmcode(loc),
2517+
[ED.para:
2518+
ED.text("The left side had the unit: "),
2519+
ED.code(ED.text(self.l))],
2520+
[ED.para:
2521+
ED.text("The right side had the unit: "),
2522+
ED.code(ED.text(self.r))],
2523+
[ED.para: ED.text("These units are not compatible")]]
2524+
end
2525+
| none =>
2526+
[ED.sequence:
2527+
[ED.para:
2528+
ED.text("A "),
2529+
ED.code(ED.text(self.opname)),
2530+
ED.text(" operation errored.")],
2531+
[ED.para:
2532+
ED.text("The left side had the unit: "),
2533+
ED.code(ED.text(self.l))],
2534+
[ED.para:
2535+
ED.text("The right side had the unit: "),
2536+
ED.code(ED.text(self.r))],
2537+
[ED.para: ED.text("These units are not compatible")]]
2538+
end]
24792539
end,
24802540
method render-reason(self):
2481-
[ED.error:
2482-
[ED.para:
2483-
ED.text("The " + self.op-name + " operation failed due to incompatible units. "),
2484-
ED.text(tostring(self.l)),
2485-
ED.text(" is not compatible with "),
2486-
ED.text(tostring(self.r))]]
2541+
[ED.error: ED.maybe-stack-loc(0, false,
2542+
lam(loc):
2543+
[ED.sequence:
2544+
ed-simple-intro(self.op-name + " operation", loc),
2545+
ED.cmcode(loc),
2546+
[ED.para:
2547+
ED.text("The left side had the unit: "),
2548+
ED.code(ED.text(self.l))],
2549+
[ED.para:
2550+
ED.text("The right side had the unit: "),
2551+
ED.code(ED.text(self.r))],
2552+
[ED.para: ED.text("These units are not compatible")]]
2553+
end,
2554+
[ED.sequence:
2555+
[ED.para:
2556+
ED.text("A "),
2557+
ED.code(ED.text(self.opname)),
2558+
ED.text(" operation errored.")],
2559+
[ED.para:
2560+
ED.text("The left side had the unit: "),
2561+
ED.code(ED.text(self.l))],
2562+
[ED.para:
2563+
ED.text("The right side had the unit: "),
2564+
ED.code(ED.text(self.r))],
2565+
[ED.para: ED.text("These units are not compatible")]])]
24872566
end
24882567
| invalid-unit-state(op-name, n, desc) with:
24892568
method render-fancy-reason(self, maybe-stack-loc, src-available, maybe-ast):

src/js/base/js-numbers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ define("pyret-base/js/js-numbers", function() {
12351235
var u2 = getUnit(n2);
12361236

12371237
if (!checkUnit(u1, u2)) {
1238-
errbacks.throwIncompatibleUnits(opName, n1, n2);
1238+
errbacks.throwIncompatibleUnits(opName, unitToString(u1), unitToString(u2));
12391239
}
12401240
}
12411241

src/js/trove/ffi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@
505505
}
506506
function throwIncompatibleUnits(opName, l, r) {
507507
runtime.checkString(opName);
508-
runtime.checkNumber(l);
509-
runtime.checkNumber(r);
508+
runtime.checkString(l);
509+
runtime.checkString(r);
510510
raise(err("incompatible-units")(opName, l, r));
511511
}
512512
function throwInvalidUnitState(opName, n, desc) {

0 commit comments

Comments
 (0)