Skip to content

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

Open
@JetForMe

Description

@JetForMe

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.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationgood first issueGood for newcomerstype checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions