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-13917] Poor diagnostic when type inference infers non-intuitive generic parameter. #56315

Open
typesanitizer opened this issue Nov 29, 2020 · 4 comments
Labels
compiler The Swift compiler in itself improvement type checker Area → compiler: Semantic analysis

Comments

@typesanitizer
Copy link

Previous ID SR-13917
Radar rdar://problem/71912785
Original Reporter @typesanitizer
Type Improvement
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, TypeChecker
Assignee None
Priority Medium

md5: 5de0728de90f586ca372a09a1e33b463

Issue Description:

https://twitter.com/wilshipley/status/1332934549223862273

extension Set {
  func overlapCount(_ lhs: [Int], _ rhs: [Int]) -> Int {
    Set(lhs).intersection(rhs).count // error: type of expression is ambiguous without more context
  }
}

We should infer that T == Int here. If that's not possible, we should at least provide a more precise diagnostic.

@typesanitizer
Copy link
Author

@swift-ci create

@xedin
Copy link
Member

xedin commented Dec 8, 2020

Unfortunately this is existing behavior which we can't change due to source compatibility reasons. Usage of `Set` in extension of `Set` means that generic arguments are equated unless parameters are explicitly specified.

@typesanitizer
Copy link
Author

Can we improve the diagnostic though? The "type of expression is ambiguous without more context" isn't very helpful.

@xedin
Copy link
Member

xedin commented Dec 8, 2020

I don't really see how we could detect this in the constraint system since type variables would just get passed down to the references of Set, we can't allocate a fix per use...

@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