Commit Graph

208 Commits

Author SHA1 Message Date
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +00:00
Chris Lattner
e120cd5cf0 revert changes to testsuite for if/let pattern restriction.
Swift SVN r25512
2015-02-24 20:41:12 +00:00
Chris Lattner
670dfcc6ab final validation test adjustments, it actually passes after these changes.
Swift SVN r25446
2015-02-21 00:19:29 +00:00
Chris Lattner
6712817f89 additional changes for the validation testsuite, that I missed
in the previous pass.


Swift SVN r25444
2015-02-21 00:12:43 +00:00
Chris Lattner
6d0a7c39e8 adjust the validation tests to the new if/let syntactic restrictions.
Thanks to Dmitri for doing almost all of this.


Swift SVN r25443
2015-02-20 23:56:30 +00:00
Dmitri Hrybenko
a99093581b stdlib: change {Dictionary,Set}.Generator to value semantics
Generator observes a snapshot of the collection.  Mutating the
collection should not have any effect on existing generators.

rdar://19726013

Swift SVN r25171
2015-02-11 07:12:25 +00:00
Dmitri Hrybenko
34d393bd22 stdlib: stop using AutoreleasingUnsafeMutablePointer.null()
Swift SVN r24956
2015-02-04 11:17:54 +00:00
Dave Abrahams
ed8c302a93 [stdlib] Move tests that challenge a debug compiler
...into the validation suite.  This is the wrong solution but at least
the bots will continue to run all the tests and we won't regress.

Swift SVN r24934
2015-02-04 01:53:14 +00:00