Skip to content

[Sema] Improved error message for static functions on existential metatypes #2127

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

Merged
merged 2 commits into from
Apr 11, 2016
Merged

Conversation

joewillsher
Copy link
Contributor

What's in this pull request?

This improves the error message produced when static members are looked up on existential metatypes.

protocol P { }
extension P {
    static func staticMethod(a:Int) { ... }
}

_ = P.staticMethod(a:) // error: static member 'staticMethod(a:)' cannot be used on instance of type 'P.Protocol'

Now the compiler emits the warning error: static member 'staticMethod(a:)' cannot be used on protocol metatype 'P.Protocol'. This better reflects why this is forbidden—the protocol cannot provide the static member.

This addresses some FIXMEs in test/expr/unary/selector/selector.swift.

The compiler still emits the correct error messages for lookups on the P.Type and P.Protocol cases and no new cases are diagnosed as errors.

_ = P.Type.staticMethod(a:) // error: type 'P.Type' has no member 'staticMethod(a:)'
_ = P.Protocol.staticMethod(a:) // error: type 'P.Protocol' has no member 'staticMethod(a:)'

Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
OS X platform @swift-ci Please test OS X platform
Linux platform @swift-ci Please test Linux platform

Note: Only members of the Apple organization can trigger swift-ci.

…atypes

Type level lookups can fail because the lookup is on an existential
metatype, like `MyProtocol.staticMethod(_:)` is invalid; however the
error message is unclear: “static member 'staticMethod(_:)' cannot be
used on instance of type ‘MyProtocol.Protocol’”.

This fix checks the base of member lookups that failed with the reason
UR_TypeMemberOnInstance for being existential metatypes. It produces
the clearer message “static member ‘staticMethod(_:)’ cannot be used on
protocol metatype ‘MyProtocol.Protocol’”. This change makes it clear
that the use of a static member on the *existential* metatype is the
problem.
@tkremenek
Copy link
Member

@swift-ci test

@tkremenek tkremenek self-assigned this Apr 10, 2016
@tkremenek
Copy link
Member

@swift-ci test

@tkremenek tkremenek merged commit de18967 into swiftlang:master Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants