Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-2372] Using ternary operator breaks initialization of an array of optional tuples in some cases #44979

Closed
swift-ci opened this issue Aug 17, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2372
Radar None
Original Reporter ac (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

OS X El Capitan 10.11.6
Xcode 7.3.1 (7D1014), Xcode 8.0 beta 6 (8S201h)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: d520c00c1d1d977797179e8de1d74272

duplicates:

  • SR-2336 Ternary operator with optionals results in lousy diagnostic

Issue Description:

The following code does not compile:

let tuples1: [(Int, Int)?]
tuples1 = [                      // Swift 2.2: error: use of '=' in a boolean context, did you mean '=='?
  true ? (1, 2) : nil            // Swift 3: 'Int1' is not convertible to 'Bool'
]

let tuples11: [(Int, Int)?]?
tuples11 = [                     // 'Int1' is not convertible to 'Bool'
  true ? (1, 2) : nil
]

let tuples12: [(Int, Int)?]? = [ // 'Int1' is not convertible to 'Bool'
  true ? (1, 2) : nil
]

The following code compiles fine:

let tuples2: [(Int, Int)?] = [true ? (1, 2) : nil]

let tuples3: [(Int, Int)?]
tuples3 = [(1, 2)]

let tuples31: [(Int, Int)?]?
tuples31 = [(1, 2)]

let tuples32: [(Int, Int)?]? = [(1, 2)]

let tuples4: [(Int, Int)]
tuples4 = [true ? (1, 2) : (3, 4)]

If we don't use tuples, there are no problems:

let ints1: [Int?]
ints1 = [true ? 1 : nil]

let ints2: [Int?] = [true ? 1 : nil]

let ints3: [Int?]? = [true ? 1 : nil]

let ints4: [Int]? = [true ? 1 : 2]
@belkadan
Copy link
Contributor

I think this is just SR-2336, where choosing between T and nil with the ternary operator isn't inferred to have type T?.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants