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-11507] Type inference breaks using flatMap in ternary operator #53908

Open
swift-ci opened this issue Sep 23, 2019 · 1 comment
Open

[SR-11507] Type inference breaks using flatMap in ternary operator #53908

swift-ci opened this issue Sep 23, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11507
Radar None
Original Reporter eimantas (JIRA User)
Type Bug
Environment

macOS 10.14.6
Xcode 11.0

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

md5: ce3bf80ddd36708fbf03ea71d8edf9af

Issue Description:

Using following code I would expect to get identical output from print statements. However it differs:

let maybeDouble: CGFloat? = 5.0

let trueFlag = true

let flatDouble = maybeDouble.flatMap({ $0 }) ?? 0

let d = trueFlag ? flatDouble ?? 0 : 0
let e = trueFlag ? (maybeDouble.flatMap({ $0 }) ?? 0) : 0

print(d) // prints "5.0"
print(e) // prints "Optional(5.0)"

Being explicit helps too:

let f: CGFloat = trueFlag ? (maybeDouble.flatMap({ $0 }) ?? 0) : 0
print(f) // prints "5.0"
@belkadan
Copy link
Contributor

@xedin, I think we have an older dup of this?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants