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-7247] Misleading type inference error message for extensions #49795

Closed
swift-ci opened this issue Mar 21, 2018 · 6 comments
Closed

[SR-7247] Misleading type inference error message for extensions #49795

swift-ci opened this issue Mar 21, 2018 · 6 comments
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

@swift-ci
Copy link
Collaborator

Previous ID SR-7247
Radar rdar://problem/38716444
Original Reporter gmilos (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

4.1 development snapshot (LLVM 260a172ffb, Clang cd84be6c42, Swift 04baf31).

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee gmilos (JIRA)
Priority Medium

md5: 2640556cbadebf5abba890a0ac38cfe1

Issue Description:

The following distills the issue I hit (in larger body of code):

/***************** File1.swift *****************/
struct SomeType<T> {
}
/***************** File2.swift *****************/
extension SomeType {
 static func someFunc<R>(r: () -> R) {
 }
}
SomeType.someFunc { "hi" }

The compiler gives the following error:

error: repl.swift:11:19: error: cannot convert value of type '() -> String' to expected argument type '() -> _'
SomeType.someFunc { "hi" }
 ^~~~~~~~ 

But of course the issue is unknown generic type on SomeType, i.e. the fix is:

SomeType<Any>.someFunc { "hi" }

Reproduces on current 4.1 development snapshot (LLVM 260a172ffb, Clang cd84be6c42, Swift 04baf31).

@belkadan
Copy link
Contributor

@xedin, do you have a dup for this?

@xedin
Copy link
Member

xedin commented Mar 21, 2018

Unfortunately diagnostics for generic parameters are currently not great 🙁 I'll create a radar anyway and dup it later.

@xedin
Copy link
Member

xedin commented Mar 21, 2018

@swift-ci create

@mdiep
Copy link
Contributor

mdiep commented Jun 10, 2018

This is unrelated to the fact that the function is an extension. This also reproduces the issue:

struct SomeType<T> {
 static func someFunc<R>(r: () -> R) {
 }
}

SomeType.someFunc { "hi" }

Note that the error is that T can't be inferred, not R.

Removing the parameter does give a proper error about T.

@mdiep
Copy link
Contributor

mdiep commented Jun 12, 2018

Curiously, if you put the closure inside () s to make it non-trailing, then you get the correct error.

@xedin
Copy link
Member

xedin commented Feb 5, 2020

Looks like compiler produces much better message how (since 5.2):

error: generic parameter 'T' could not be inferred
SomeType.someFunc { "hi" }
^
 note: 'T' declared as parameter to type 'SomeType'
struct SomeType<T> {
                ^
note: explicitly specify the generic arguments to fix this issue
SomeType.someFunc { "hi" }
^
        <Any>

gmilos (JIRA User) Please use the latest master/5.2 snapshot to verify and close.

@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

4 participants