Xcode 8.0, Swift 3: Cannot assign value of type 'String' to type 'String!'
Originator: | acapulco1988 | ||
Number: | rdar://28582961 | Date Originated: | 10/2/16 |
Status: | Open | Resolved: | |
Product: | Developer Tools | Product Version: | Xcode 8.0 (8A218a) |
Classification: | Reproducible: | Always |
The attached code sample causes the following error on Swift 3 on Xcode 8.0 (8A218a) Playground execution failed: error: InfixOperatorBug.playground:30:23: error: cannot assign value of type 'String' to type 'String!' output = "test" --> 2 ~ 1 ~~~~~~~~~~~~~^~~ as String! Steps to Reproduce: 1. Run the sample playground 2. Observe error on compilation Expected Results: Code should compile, output "test-->2~1" Actual Results: Error: Playground execution failed: error: InfixOperatorBug.playground:30:23: error: cannot assign value of type 'String' to type 'String!' output = "test" --> 2 ~ 1 ~~~~~~~~~~~~~^~~ as String! Version: Xcode 8.0 (8A218a), macOS Sierra 10.12 (16A323) Notes: Related issue: Changing output (line 35) from "let output: String!" to "let output: String" causes an ambiguous error when it should not. Playground execution failed: error: InfixOperatorBug.playground:30:23: error: ambiguous reference to member '~' output = "test" --> 2 ~ 1 ^ InfixOperatorBug.playground:5:6: note: found this candidate func ~ (lhs: String, rhs: Int) -> String { ^ InfixOperatorBug.playground:9:6: note: found this candidate func ~ (lhs: NSData, rhs: NSData) -> NSData { code: import Cocoa // MARK: ~ precedencegroup TildePriorityPrecedence { higherThan: AssignmentPrecedence } infix operator ~: TildePriorityPrecedence func ~ (lhs: String, rhs: Int) -> String { return "\(lhs)~\(rhs)" } func ~ (lhs: NSData, rhs: NSData) -> NSData { return NSData() } // MARK: --> precedencegroup ArrowPriorityPrecedence { higherThan: TildePriorityPrecedence } infix operator -->: ArrowPriorityPrecedence func -->(lhs: String, rhs: Float) -> String { return "\(lhs)-->\(rhs)" } func -->(lhs: CGColor, rhs: CGColor) -> CGColor { return CGColor.black } let output: String output = "test" --> 2 ~ 1 print(output)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!