interpolation in assertion failure message
See original GitHub issue[@gavinking] When we implemented assertions, we left one issue for later: how to interpolate expressions into the assertion failure message. Right now, we can write:
"exponent must be non-negative"
assert (power>=0);
Where the string literal is an abbreviated doc
annotation. I’ve defended this solution on the grounds that it lets ceylondoc include the preconditions on parameters in its generated documentation. However, in truth, we’re eventually going to need interpolation here. So the question is: what should the syntax be. Clearly, the following is one possibility:
"exponent ``power`` must be non-negative"
assert (power>=0);
Could ceylondoc do something reasonable with this? I don’t see why not. But is it just to “weird” to suddenly let you have interpolation in a doc
string, all of a sudden, in one special case?
Alternatively, we could let you write something like this:
assert (power>=0) "exponent ``power`` must be non-negative";
or this:
assert (power>=0) => "exponent ``power`` must be non-negative";
The =>
is not strictly necessary. But for some reason I find it more natural to format across multiple lines. This:
assert (power>=0)
"exponent ``power`` must be non-negative";
is to me less natural than this:
assert (power>=0)
=> "exponent ``power`` must be non-negative";
Whatever, either option would be acceptable to me.
WDYT?
[Migrated from ceylon/ceylon-spec#586]
Issue Analytics
- State:
- Created 11 years ago
- Comments:21 (13 by maintainers)
Done!
I have implemented support for this in the typechecker. However, the backends need to be modified to support this (which I assume is a pretty trivial change).
@tombentley? @chochos?