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-7884] Overload resolution picks optional variant even when value is not optional #50419

Closed
slavapestov opened this issue Jun 5, 2018 · 7 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2 type checker Area → compiler: Semantic analysis

Comments

@slavapestov
Copy link
Member

Previous ID SR-7884
Radar rdar://problem/40819547
Original Reporter @slavapestov
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, TypeChecker
Assignee @slavapestov
Priority Medium

md5: 039128c33d520a4d60fb1f4f65a98c4e

is duplicated by:

  • SR-7964 Overloading a method with an optional parameter chooses wrong overload
  • SR-7899 [4.2 regression] type checker chooses different type than it used to

Issue Description:

I'm not sure if this is intended behavior or not:

func f<T>(x: T) {
  print("not optional")
}

func f<T>(x: T?) {
  print("optional")
}


let x: String = "hi"

f(x: x) // calls optional variant

In Swift 4.1, we used to pick the non optional variant.

Reported by amseddi (JIRA User) in WWDC labs

@slavapestov
Copy link
Member Author

@rudkx Any ideas?

@slavapestov
Copy link
Member Author

@swift-ci create

@rudkx
Copy link
Member

rudkx commented Jun 6, 2018

This was broken by #14499. I'm looking at fixing it.

@xedin
Copy link
Member

xedin commented Jun 7, 2018

@rudkx I think we need to remove that optimization because it's unsound, and we can't make these local choices until we have full solutions.

@rudkx
Copy link
Member

rudkx commented Jun 7, 2018

My plan is to back it out for now. I don't know if there is any safe way to do this since we are not actually taking into account the scoring that would happen due to optional injection, function conversion, etc.

I am collecting test cases to add to the test suite.

@xedin
Copy link
Member

xedin commented Jun 7, 2018

Yes, I agree, that's what I meant exactly...

@rudkx
Copy link
Member

rudkx commented Jun 8, 2018

This is merged to master: 7601d50

and swift-4.2-branch: 02150f1

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

No branches or pull requests

4 participants