From 2a84095cb62e43d0a26ff90b220f0a4f9f1d40f7 Mon Sep 17 00:00:00 2001 From: Max Moiseev Date: Mon, 10 Jul 2017 14:05:05 -0700 Subject: [PATCH 1/2] [overlay] Hide the _ExpressibleByColorLiteral initializer from code completion. Fixes: (cherry picked from commit 391d49a31e5117585d05a2d003047698142fd1a6) --- lib/Sema/TypeChecker.cpp | 2 +- stdlib/public/SDK/AppKit/AppKit.swift | 2 +- stdlib/public/SDK/CoreGraphics/CoreGraphics.swift | 2 +- stdlib/public/SDK/UIKit/UIKit.swift | 2 +- stdlib/public/core/CompilerProtocols.swift | 2 +- test/IDE/complete_literal.swift | 2 +- test/IDE/complete_value_literals.swift | 2 +- test/IDE/structure_object_literals.swift | 2 +- test/Sema/object_literals_ios.swift | 2 +- test/Sema/object_literals_osx.swift | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp index e04c7aca6d543..e59f1c48843a9 100644 --- a/lib/Sema/TypeChecker.cpp +++ b/lib/Sema/TypeChecker.cpp @@ -172,7 +172,7 @@ DeclName TypeChecker::getObjectLiteralConstructorName(ObjectLiteralExpr *expr) { switch (expr->getLiteralKind()) { case ObjectLiteralExpr::colorLiteral: { return DeclName(Context, Context.Id_init, - { Context.getIdentifier("colorLiteralRed"), + { Context.getIdentifier("_colorLiteralRed"), Context.getIdentifier("green"), Context.getIdentifier("blue"), Context.getIdentifier("alpha") }); diff --git a/stdlib/public/SDK/AppKit/AppKit.swift b/stdlib/public/SDK/AppKit/AppKit.swift index ba9298bd4fa67..d225eec07b9bd 100644 --- a/stdlib/public/SDK/AppKit/AppKit.swift +++ b/stdlib/public/SDK/AppKit/AppKit.swift @@ -79,7 +79,7 @@ extension NSApplication { extension NSColor : _ExpressibleByColorLiteral { @nonobjc - public required convenience init(colorLiteralRed red: Float, green: Float, + public required convenience init(_colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) { self.init(srgbRed: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha: CGFloat(alpha)) diff --git a/stdlib/public/SDK/CoreGraphics/CoreGraphics.swift b/stdlib/public/SDK/CoreGraphics/CoreGraphics.swift index 96943ce274069..7ed88df501bb6 100644 --- a/stdlib/public/SDK/CoreGraphics/CoreGraphics.swift +++ b/stdlib/public/SDK/CoreGraphics/CoreGraphics.swift @@ -53,7 +53,7 @@ public protocol _CGColorInitTrampoline { } extension _CGColorInitTrampoline { - public init(colorLiteralRed red: Float, green: Float, blue: Float, + public init(_colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) { self.init(red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha: CGFloat(alpha)) diff --git a/stdlib/public/SDK/UIKit/UIKit.swift b/stdlib/public/SDK/UIKit/UIKit.swift index f37db95da49a3..90b4ccdf996b6 100644 --- a/stdlib/public/SDK/UIKit/UIKit.swift +++ b/stdlib/public/SDK/UIKit/UIKit.swift @@ -216,7 +216,7 @@ extension UIView : _DefaultCustomPlaygroundQuickLookable { #endif extension UIColor : _ExpressibleByColorLiteral { - @nonobjc public required convenience init(colorLiteralRed red: Float, + @nonobjc public required convenience init(_colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) { self.init(red: CGFloat(red), green: CGFloat(green), diff --git a/stdlib/public/core/CompilerProtocols.swift b/stdlib/public/core/CompilerProtocols.swift index 38a7a7ea77de0..01b0b539591a3 100644 --- a/stdlib/public/core/CompilerProtocols.swift +++ b/stdlib/public/core/CompilerProtocols.swift @@ -744,7 +744,7 @@ public protocol _ExpressibleByColorLiteral { /// /// Do not call this initializer directly. Instead, initialize a variable or /// constant using a color literal. - init(colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) + init(_colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) } /// A type that can be initialized using an image literal (e.g. diff --git a/test/IDE/complete_literal.swift b/test/IDE/complete_literal.swift index 56637a11e1efa..e992218751dee 100644 --- a/test/IDE/complete_literal.swift +++ b/test/IDE/complete_literal.swift @@ -62,7 +62,7 @@ func giveMeAString() -> Int { // LITERAL5-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: append({#contentsOf: Sequence#})[#Void#]{{; name=.+$}} struct MyColor: _ExpressibleByColorLiteral { - init(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) { red = colorLiteralRed } + init(_colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) { red = colorLiteralRed } var red: Float } public typealias _ColorLiteralType = MyColor diff --git a/test/IDE/complete_value_literals.swift b/test/IDE/complete_value_literals.swift index 4397299a73f20..6f02d3e002fd3 100644 --- a/test/IDE/complete_value_literals.swift +++ b/test/IDE/complete_value_literals.swift @@ -201,7 +201,7 @@ func testTuple2() { // TUPLE_2: Literal[Tuple]/None/TypeRelation[Identical]: ({#(values)#})[#(MyInt1, MyString1, MyDouble1)#]; struct MyColor1: _ExpressibleByColorLiteral { - init(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {} + init(_colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {} } func testColor0() { let x: Int = #^COLOR_0^# diff --git a/test/IDE/structure_object_literals.swift b/test/IDE/structure_object_literals.swift index ed0bc3fc20475..3144ff3b28dd5 100644 --- a/test/IDE/structure_object_literals.swift +++ b/test/IDE/structure_object_literals.swift @@ -1,7 +1,7 @@ // RUN: %swift-ide-test -structure -source-filename %s | %FileCheck %s struct S: _ExpressibleByColorLiteral { - init(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {} + init(_colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {} } // CHECK: let y: S = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1) diff --git a/test/Sema/object_literals_ios.swift b/test/Sema/object_literals_ios.swift index 9aea7d0822a32..7585a96d0122b 100644 --- a/test/Sema/object_literals_ios.swift +++ b/test/Sema/object_literals_ios.swift @@ -2,7 +2,7 @@ // REQUIRES: OS=ios struct S: _ExpressibleByColorLiteral { - init(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {} + init(_colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {} } let y: S = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1) diff --git a/test/Sema/object_literals_osx.swift b/test/Sema/object_literals_osx.swift index 6d4c67b8590bb..d5eb0c6aee18c 100644 --- a/test/Sema/object_literals_osx.swift +++ b/test/Sema/object_literals_osx.swift @@ -2,7 +2,7 @@ // REQUIRES: OS=macosx struct S: _ExpressibleByColorLiteral { - init(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {} + init(_colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {} } let y: S = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1) From 04b09a7dc3802888c888800b2acbe4e65e9c4c39 Mon Sep 17 00:00:00 2001 From: Max Moiseev Date: Wed, 12 Jul 2017 09:04:58 -0700 Subject: [PATCH 2/2] Add an @available initializer for source compatibility (cherry picked from commit d9e0eef4aaa1508deba97e93454f617d07bd5eb9) --- stdlib/public/core/CompilerProtocols.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stdlib/public/core/CompilerProtocols.swift b/stdlib/public/core/CompilerProtocols.swift index 01b0b539591a3..2eb12b3bc1223 100644 --- a/stdlib/public/core/CompilerProtocols.swift +++ b/stdlib/public/core/CompilerProtocols.swift @@ -747,6 +747,17 @@ public protocol _ExpressibleByColorLiteral { init(_colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) } +extension _ExpressibleByColorLiteral { + @available(swift, deprecated: 3.2, obsoleted: 4.0, + message: "This initializer is only meant to be used by color literals") + public init( + colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float + ) { + self.init( + _colorLiteralRed: red, green: green, blue: blue, alpha: alpha) + } +} + /// A type that can be initialized using an image literal (e.g. /// `#imageLiteral(resourceName: "hi.png")`). public protocol _ExpressibleByImageLiteral {