<div dir="ltr">+1<div><br><div class="gmail_quote"><div dir="ltr">On Mon, May 16, 2016 at 2:07 PM Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Currently, we parse a type after 'as[?!]' and 'is'. This is mostly what you'd expect, but does lead to problems when an 'as' expression appears as part of a comparison:<br>
<br>
20 as Int64 < y as Int64 // error, '>' expected to close generic parameter list Int64<y><br>
<br>
Looking to the future, many people have also expressed interest in the ability to do dynamic type checks against metatype values, not only static types, as in:<br>
<br>
class Base {}<br>
class DerivedA {}<br>
class DerivedB {}<br>
<br>
var x: Base.Type = DerivedA<br>
<br>
DerivedA() as? x // succeeds<br>
DerivedB() as? x // fails<br>
<br>
If we accept <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0090-remove-dot-self.md" rel="noreferrer" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0090-remove-dot-self.md</a>, dropping the '.self' requirement to refer to type objects, then I think we should also change 'is' and 'as' to parse the expression grammar on their right-hand side, leaving it up to the normal expression disambiguation rule to handle angle brackets. This solves the '20 as Int64 < x' problem, and prepares us to support dynamic is/as queries in the future. (To be clear, designing dynamic queries should be its own discussion.) What do you all think?<br>
<br>
-Joe<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div></div>