Skip to content
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

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

Open
JetForMe opened this issue Jan 8, 2023 · 4 comments · May be fixed by #63301
Open

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

JetForMe opened this issue Jan 8, 2023 · 4 comments · May be fixed by #63301
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis

Comments

@JetForMe
Copy link

JetForMe commented Jan 8, 2023

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.

@JetForMe JetForMe added feature A feature request or implementation triage needed This issue needs more specific labels labels Jan 8, 2023
@xedin xedin added diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis good first issue Good for newcomers and removed triage needed This issue needs more specific labels labels Jan 8, 2023
@AnthonyLatsis AnthonyLatsis added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself and removed feature A feature request or implementation labels Jan 8, 2023
@ashuthe1
Copy link

hey! I want to work on this but I am new to open source. could you please guide me.

@Rajveer100
Copy link
Contributor

Hi there, Rajveer here, I found this error in DiagnosticsSema.def:

ERROR(instance_member_use_on_type,none,
      "instance member %1 cannot be used on type %0; "
      "did you mean to use a value of this type instead?", (Type, DeclNameRef))

@AnthonyLatsis
Copy link
Collaborator

This issue was recently worked on by @valeriyvan. Check out the pull request for commentary and consider checking in with Valeriy if you wish to work on this.

dk-talks added a commit to dk-talks/swift that referenced this issue May 1, 2023
@dk-talks
Copy link

dk-talks commented May 1, 2023

Hello @AnthonyLatsis , I have resolved this issue. Please have a look. #65539

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis
Projects
None yet
6 participants