swiftlang/swift

"Instance member cannot be used on type" diagnostic message could be more specific

Open

#62 909 ouverte le 8 janv. 2023

Voir sur GitHub
 (6 commentaires) (0 réactions) (1 assigné)Swift (10 719 forks)batch import
bugcompilerdiagnostics qualitygood first issuetype checker

Métriques du dépôt

Stars
 (69 989 stars)
Métriques de merge PR
 (Merge moyen 8j 17h) (510 PRs mergées en 30 j)

Description

Motivation

It took me far too long to understand why the compiler was giving me this error (I was quickly trying something a bit less trivial than this example involving async/await, and thought the issue was around the execution context):

@main public struct Scraper
{
    public static func main()
    {
        let data = fetch()     //  Instance member 'fetch' cannot be used on type 'Scraper'
                   ^~~~~
    }
    
    func fetch() -> Data
    {
        return Data()
    }
}

Solution

A more precise wording, something like "Instance method cannot be called from static context", would be much more helpful.

Guide contributeur