mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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
55 lines
1.8 KiB
Swift
55 lines
1.8 KiB
Swift
//===----------------------------------------------------------*- swift -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
%import gyb
|
|
%TMirrorDecl = gyb.parseTemplate("../../common/MirrorDecl.gyb")
|
|
%TMirrorConformance = gyb.parseTemplate("../../common/MirrorConformance.gyb")
|
|
%TMirrorBoilerplate = gyb.parseTemplate("../../common/MirrorBoilerplate.gyb")
|
|
|
|
% for Self in ['SKShapeNode','SKSpriteNode','SKTextureAtlas','SKTexture']:
|
|
% MirrorDecl = gyb.executeTemplate(TMirrorDecl,introspecteeType=Self)
|
|
% MirrorConformance = gyb.executeTemplate(TMirrorConformance,introspecteeType=Self)
|
|
% MirrorBoilerplate = gyb.executeTemplate(TMirrorBoilerplate,introspecteeType=Self)
|
|
|
|
${MirrorDecl} {
|
|
${MirrorBoilerplate}
|
|
|
|
var count: Int { return 0 }
|
|
|
|
subscript(_: Int) -> (String, MirrorType) {
|
|
_preconditionFailure("MirrorType access out of bounds")
|
|
}
|
|
|
|
var summary: String { return _value.description }
|
|
|
|
var quickLookObject: QuickLookObject? {
|
|
// this code comes straight from the quicklooks
|
|
|
|
if let data? = (_value as AnyObject)._copyImageData?() {
|
|
// we could send a Raw, but I don't want to make a copy of the
|
|
// bytes for no good reason make an NSImage out of them and
|
|
// send that
|
|
#if os(OSX)
|
|
let img = NSImage(data: data)
|
|
#elseif os(iOS)
|
|
let img = UIImage(data: data)
|
|
#endif
|
|
return .Some(.Sprite(img))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
}
|
|
|
|
${MirrorConformance}
|