You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The error message for case expression with missing or void-typed else clause is confusing and doesn't tell the programmer what's actually wrong or how to fix it.
/repro/case_expression.nim(8, 12) Error: expression 'foo()' is of type 'int' and has to be discarded
Expected Output
Not sure, but maybe something like:
/repro/case_expression.nim(8, 12) Error: `else` clause has no type or is ambiguous
If you add the compiler's recommended discard to the function calls, you get something that is more actionable but kind of gross looking:
/repro/case_expression.nim(7, 14) Error: expression 'case rand(1 .. 3)
of 1:
discard foo()
of 2:
discard bar()
of 3:
discard baz()
else:
const
expr279228 = "false"
const
loc279231 = (filename: "/repro/case_expression.nim",
line: 11, column: 15)
ploc279232 = "/repro/case_expression.nim(11, 16)"
{.line: (filename: "/repro/case_expression.nim", line: 11,
column: 15).}:
if true:
failedAssertImpl("/repro/case_expression.nim(11, 16) `false` can\'t happen")' has no type (or is ambiguous)
Also, if there is a concrete but mismatching type then the error is much better:
repro_case_expression.nim(11, 12) Error: type mismatch: got <Gadget> but expected 'int'
Possible Solution
Additional Information
$ nim -v
Nim Compiler Version 0.20.2 [Linux: amd64]
Compiled at 2019-07-17
Copyright (c) 2006-2019 by Andreas Rumpf
git hash: 88a0edba4b1a3d535b54336fd589746add54e937
active boot switches: -d:release
The text was updated successfully, but these errors were encountered:
chr-1x
changed the title
Confusing error message for case expression with inconsistently-typed else clause
Confusing error message for case expression with missing or void-typed else clause
Aug 12, 2019
I would argue that if you have a noreturn void proc in the else branch, the compiler should still evaluate the whole case statement as expression. This is how the Nothing type in scala works as well.
I would argue that if you have a noreturn void proc in the else branch, the compiler should still evaluate the whole case statement as expression. This is how the Nothing type in scala works as well.
It does, it's just that Nim doesn't know in advance that assert false doesn't return
The error message for case expression with missing or void-typed
else
clause is confusing and doesn't tell the programmer what's actually wrong or how to fix it.Example
Current Output
Expected Output
Not sure, but maybe something like:
If you add the compiler's recommended
discard
to the function calls, you get something that is more actionable but kind of gross looking:Also, if there is a concrete but mismatching type then the error is much better:
Possible Solution
Additional Information
The text was updated successfully, but these errors were encountered: