swiftlang/swift

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

Offen

#62.909 geöffnet am 08.01.2023

 (6 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Swift (10.719 Forks)batch import
bugcompilerdiagnostics qualitygood first issuetype checker

Repository-Metriken

Stars
 (69.989 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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.

Contributor Guide