Navigation Menu

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-9351] Improper error messages when querying the type of an unbound generic #51819

Closed
swift-ci opened this issue Nov 26, 2018 · 3 comments
Closed
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-9351
Radar rdar://problem/46427366
Original Reporter Alvae (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

This behavior was observed on Swift 4.2.1, on a macOS 10.14.1 platform.

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

md5: 146288aaba68c3cd83cfd77bcc3a782d

Issue Description:

If you attempt to get the type of an unbound generic type, using Swift's built-in `type(of: )` function, the type solver doesn't produce as meaningful errors as it is able to do in some other contexts.

For instance, if you write:

struct Foo<T> {
  func f(x: Foo) -> T {
    return bar
  }
  let bar: T
}
print(type(of: Foo.f))

The compiler produces the following error message, which is arguably less than ideal, as it's quite surprising for any type to not conform to Any:

argument type '((Foo<_>) -> (Foo<_>) -> _).Type' does not conform to expected type 'Any'

Similar problems can be observed in other contexts, but with different messages. For instance, the following expression

let t: Any = type(of: Foo.f)

produces this error, which is better than in the previous example, but still arguably perfectible:

expression type '(_) -> _' is ambiguous without more context

The compiler is able to produce more meaningful messages in more common situations. For instance

let arr = [Foo.f]

produces

generic parameter 'T' could not be inferred
@belkadan
Copy link
Contributor

cc @xedin

@LucianoPAlmeida
Copy link
Collaborator

@xedin Seems fixed on Xcode 11.4.1 🙂

struct Foo<T> {
  func f(x: Foo) -> T {
    return bar
  }
  let bar: T
}
print(type(of: Foo.f)) // Generic parameter 'T' could not be inferred

@xedin
Copy link
Member

xedin commented Apr 27, 2020

Alvae (JIRA User) Please use Xcode 11.4 release or one of the latest master branch snapshots that this issue has been fixed. Thank you!

@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