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-50] Use 'try' statement to guide type inference #42673

Open
akyrtzi opened this issue Dec 4, 2015 · 1 comment
Open

[SR-50] Use 'try' statement to guide type inference #42673

akyrtzi opened this issue Dec 4, 2015 · 1 comment
Labels
compiler The Swift compiler in itself improvement type checker Area → compiler: Semantic analysis

Comments

@akyrtzi
Copy link
Member

akyrtzi commented Dec 4, 2015

Previous ID SR-50
Radar None
Original Reporter @akyrtzi
Type Improvement
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, TypeChecker
Assignee None
Priority Medium

md5: 9004a0727c0e0a404b014393e17c9bce

Issue Description:

With this code:

enum SomeError : ErrorType {
  case Error
}

enum SomethingOrError<T> {
  case err(SomeError)
  case some(T)
}

func doit() -> SomethingOrError<Int> {
  return SomethingOrError.some(0)
}

func doit() throws -> Int {
  return 0
}

let something = try! doit()

You get:

t.swift:18:22: error: ambiguous use of 'doit()'
let something = try! doit()
                     ^
t.swift:10:6: note: found this candidate
func doit() -> SomethingOrError<Int> {
     ^
t.swift:14:6: note: found this candidate
func doit() throws -> Int {
     ^

Consider guiding type inference to resolve the call to the throwing function since the call uses 'try'.

@belkadan
Copy link
Contributor

belkadan commented Dec 4, 2015

Since you're allowed to put try around a whole expression, I'm not convinced this is (1) implementable, or (2) a good idea. I don't think we can reasonably count try as a "contextual type" that implies something throws.

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

No branches or pull requests

2 participants