interpolation in assertion failure message #3692
Comments
[@gavinking] I've so far had zero (0.0) feedback on this issue. Thoughts? |
[@tombentley] I do like
assuming ceylondoc is still allowed to document this when it occurs as a precondition. |
Well, that's the real question: what is ceylondoc going to do with this shit? I suppose it can render a link to the parameter, no? |
[@DiegoCoronel] We had a similar discussion in #3725 , i did not know about this issue. |
[@gavinking] Well, I kinda implemented this in branch |
[@gavinking] Not for 1.0. |
[@ncorai] Now that all validation is done through assert statements, it would be really nice to have interpolation in the message for milestone 1.1. The longer we wait the more the existing code will be littered with not-quite-useful error messages. |
I regret to say that release 1.5 feels as far away today as it did 3 years ago. How about 1.3.1 instead? Pretty please |
Yes it doesn't seem so hard to do and would be really useful. |
Today I converted Java code to Ceylon and needed an interpolated assert message, but unfortunately I had to write that message as a comment instead. FTR I like the fat arrow used in the initial comment, it kinda looks like what I would write when taking notes on paper:
|
Huh? What's wrong with |
I hadn't thought of this :) |
|
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). |
Now available on the |
I've implemented support in the JVM backend. JS still to go. |
@lucaswerkmeister note that this change will affect |
Done! |
See eclipse/ceylon#3692. Apparently they work without any changes to formatter code, yay!
Seems this was the chosen syntax? "exponent ``power`` must be non-negative"
assert (power>=0); |
Thanks for the heads-up @gavinking! (Formatter works without changes, nice!) |
Looks really cool. Reminds me of groovy's "power assert". Just updated the assertion messages in the |
[@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:
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: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:
or this:
The
=>
is not strictly necessary. But for some reason I find it more natural to format across multiple lines. This:is to me less natural than this:
Whatever, either option would be acceptable to me.
WDYT?
[Migrated from ceylon/ceylon-spec#586]
The text was updated successfully, but these errors were encountered: