Uh oh!
There was an error while loading. Please reload this page.
RFC: "as" should be "as PATH" or "as (TYPE)" - #96
Conversation
There was a problem hiding this comment.
Oops. It'll allow us to add more type operators later in the future.
lilyball
commented
May 28, 2014
An alternative would be to define a restricted type form that disallows DST is supposed to allow us to make It may want to disallow |
pcwalton
commented
May 28, 2014
You can't coerce with |
bstrie
commented
May 28, 2014
Can you give an example of existing code that this would affect? |
pcwalton
commented
May 28, 2014
Yes. I did in the RFC. |
lilyball
commented
May 28, 2014
@pcwalton I don't know what the current plan is anymore, but one of the benefits DST was supposed to bring was the ability to have free conversions from |
pcwalton
commented
May 28, 2014
"as" doesn't do every kind of coercion. It only does two specific kinds of conversions: numeric conversions and trait conversions. |
lilyball
commented
May 28, 2014
lilyball
commented
May 28, 2014
The DST proposals that introduced the idea of free coercion from |
pcwalton
commented
May 28, 2014
OK, I guess it does. But I am opposed to making the type grammar more complicated just for this. |
lilyball
commented
May 28, 2014
http://smallcultfollowing.com/babysteps/blog/2014/01/05/dst-take-5/ contains code snippets that use |
pcwalton
commented
May 28, 2014
I doubt much if any existing code will break. The only code that would break would be something like "foo as ~Trait". |
lilyball
commented
May 28, 2014
Restricting to |
pcwalton
commented
May 28, 2014
|
pcwalton
commented
May 28, 2014
Forget it. I don't want to make the type grammar any more complicated than it is. |
Summary
The
asproduction in the grammar should beas PATHoras (TYPE)(with the parentheses).Motivation
When adding
+to separate trait object paths from bounds in the type grammar, we broke a bunch of code that looked like1 as uint + 3. This is because the type parser is greedy and started parsing after+. This will allow usDetailed design
The
asproduction in the grammar should beas PATHoras (TYPE)(with the parentheses).PATHproductions in this context should be parsed as types.Drawbacks
Complex types with
asmight become slightly more verbose, and the grammar becomes slightly more complicated.Alternatives
The impact of not doing this is that if we extend the type grammar (e.g. with
+) then we will break existing code.Unresolved questions
N/A.