In other words, ::ReturnType
is incompatible with where
clauses in the short function form declarations.
I thought an exemple was more clear than my words in the title.
Yes, this is tricky, since a where b
denotes a type, and x::t
means x has type t, so x::a where b
is most naturally parsed as x::(a where b)
.
It's easy to just parenthesize the function and return type.
Quoting from #23163:
What about disallowing type annotations on short-form functions entirely? They're not super useful anyway. Throwing an error would be better here than giving a surprising interpretation.
Or at least throwing an error when the short form is used with a type annotation and a where clause 鈥撀爕ou can't recover once you've reached the =
but at least it can throw a helpful error.
What would the error suggest, those features can only be used together in long form functions? Should probably only disallow the ambiguous / confusing cases, if things are parenthesized such that the intent is clear, I don't see a reason to error.
Yes, it would only the be necessary to raise an error when there are no disambiguating parens.
@bramtayl: what do you suggest as an alternative? I see only four plausible options:
Option 1 seems clearly bad and 4 is not going to happen, which leaves only the middle two.
Hmm. I wasn't reading closely, I was just immediately off-put because I almost exclusively use short form functions (with begin blocks where necessary), and in the long term it would be nice to maintain the same functionality for short form and long form.