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-9598] Confusing errors around dot-prefix and optional #52045

Closed
stephencelis opened this issue Jan 3, 2019 · 4 comments
Closed

[SR-9598] Confusing errors around dot-prefix and optional #52045

stephencelis opened this issue Jan 3, 2019 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-9598
Radar None
Original Reporter @stephencelis
Type Bug
Status Closed
Resolution Done
Environment

Swift 4.2

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

md5: 404f375953ec192e9ba72327dc495c98

Issue Description:

Given the following code:

struct Baz<A> {
}

extension Baz where A == Int {
  static let baz = Baz()
  static let obaz = Baz?.some(baz)
}

func foo<A>(_ bar: A, _ baz: Baz<A>) {}

foo(1, .baz)

foo(Int?.some(1), .baz)

The final line returns the error:

Generic parameter 'A' could not be inferred

This makes sense upon closer examination, though with how much optional sugar is mixed into the language, I'd hope at the very least for some better error messaging when Swift can detect the discrepancy around optionals, and maybe a fix-it to unwrap bar in the above case.

@stephencelis
Copy link
Contributor Author

I'm filing this for a user of our library, who hit this message here: pointfreeco/swift-snapshot-testing#161

@belkadan
Copy link
Contributor

belkadan commented Jan 7, 2019

cc @xedin

@xedin
Copy link
Member

xedin commented Jan 7, 2019

@stephencelis Thanks for the report, looks like this was fixed on master already:

error: value of optional type 'Optional<Int>' must be unwrapped to a value of type 'Int'
foo(Int?.some(1), .baz)
         ^
note: coalesce using '??' to provide a default when the optional value contains 'nil'
foo(Int?.some(1), .baz)
         ^
                 ?? <#default value#>
note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
foo(Int?.some(1), .baz)
         ^
                !

Please use one of the nightly snapshots to verify and close this issue.

@stephencelis
Copy link
Contributor Author

Nice![]( Worked like a charm on the latest toolchain. Thanks)

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

No branches or pull requests

3 participants