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-10757] Type Inference Failure Around Float/Integer Literals and Optionals #53147

Closed
stephencelis opened this issue May 23, 2019 · 2 comments
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

@stephencelis
Copy link
Contributor

Previous ID SR-10757
Radar rdar://problem/72770327
Original Reporter @stephencelis
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5.1

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

md5: 42e2e8205935be068d993c032947aa28

Issue Description:

Paste the following into a playground:

struct Parser<A> {
  let run: (inout Substring) -> A?

  func map<B>(_ f: @escaping (A) -> B) -> Parser<B> {
    return Parser<B> { input in
      self.run(&input).map(f)
    }
  }
}

let char = Parser<Character> { str in
  guard let match = str.first else { return nil }
  str.removeFirst()
  return match
}

let northSouth = char
  .map {
    $0 == "N" ? 1.0
      : $0 == "S" ? -1
      : nil
} 

Gives you the following error:

Result values in '? :' expression have mismatching types 'Double' and 'Int?'

Wrapping 1.0 or -1 in an explicit Optional, or using as fixes.

@typesanitizer
Copy link

@swift-ci create

@xedin
Copy link
Member

xedin commented Jan 14, 2021

Fixed by #35225 Please use the next available snapshot of main branch to verify and close.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants