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-13079] Improve diagnostics for key path root inferred as optional types #55525

Closed
LucianoPAlmeida opened this issue Jun 25, 2020 · 1 comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement type checker Area → compiler: Semantic analysis

Comments

@LucianoPAlmeida
Copy link
Collaborator

Previous ID SR-13079
Radar None
Original Reporter @LucianoPAlmeida
Type Improvement
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 6a88f5bab5246df2825c3f8a7bab7248

Issue Description:

The following example gives

func SR5688_KP(_ kp: KeyPath<String?, Int>) {}

SR5688_KP(\.count) // error: value of optional type 'String?' must be unwrapped to refer to member 'count' of wrapped base type 'String

// But if we fix it to 
func SR5688_KP(_ kp: KeyPath<String?, Int>) {}

SR5688_KP(\String.count) // Key path value type 'String?' cannot be converted to contextual type 'String'

Since `String?.count` is not allowed and we can't convert from `String?` to `String` in the key path root context.

We should improve this to diagnose something that emphasizes that the problem is with the key path's root type being inferred to an optional type.

@LucianoPAlmeida
Copy link
Collaborator Author

cc @hamishknight

@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
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant