swiftlang/swift

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

開放

#62,909 建立於 2023年1月8日

 (6 則留言) (0 個反應) (1 位負責人)Swift (10,719 個分叉)batch import
bugcompilerdiagnostics qualitygood first issuetype checker

倉庫指標

星標
 (69,989 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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.

貢獻者指南