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

Offer additional note for why method with Self reference cannot be used on any SomeType #76320

Open
ktoso opened this issue Sep 6, 2024 · 4 comments
Labels
feature A feature request or implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis

Comments

@ktoso
Copy link
Contributor

ktoso commented Sep 6, 2024

Motivation

The following snippet;


protocol Base {
    associatedtype SomeID: Hashable
}

protocol Alpha: Base {
    func take(id: Self.SomeID)
}

struct Use {
    let alpha: any Alpha
    
    func test() {
        alpha.take(id: 12) // error: Member 'take' cannot be used on value of type 'any Alpha'; consider using a generic constraint instead
    }
}

is correct in rejecting the line, since we need Self.SomeID to be well typed, but we dont know what its type is via the any.

It'd be helpful if we can point out that "why" the method can't be used via a note, in a method with many parameters one can sometimes miss the Self reference.

Proposed solution

Adding a note on the offending parameter would be good

Alternatives considered

No response

Additional information

No response

@ktoso ktoso added feature A feature request or implementation triage needed This issue needs more specific labels type checker Area → compiler: Semantic analysis and removed triage needed This issue needs more specific labels labels Sep 6, 2024
@amritpan
Copy link
Member

amritpan commented Sep 8, 2024

@GunjanRawat26 This could be a good intro to diagnostics

@ktoso
Copy link
Contributor Author

ktoso commented Sep 10, 2024

Linking with radar rdar://135445764

Contributions welcome here, this could be an simple first issue maybe?

@ktoso ktoso added the good first issue Good for newcomers label Sep 10, 2024
@flash1729
Copy link

hey @ktoso , i would like to work on this as my first issue

from what i have understood is we need to give a more refined compiler message for this error and for it

  1. identify where in the compiler this error message is generated
  2. change the message there to be more specific

it would be great if you could guide me further on anything that i am missing

@flash1729
Copy link

Current progress :
I found the code related to error message in DiagnosticsSema.def

ERROR(could_not_use_member_on_existential,none,
      "member %1 cannot be used on value of type %0; consider using a"
      " generic constraint instead",
      (Type, DeclNameRef))

// error: member 'take' cannot be used on value of type 'any Alpha'; consider using a generic constraint instead

This is where changes will be made to show different error message

Questions

  1. Are there any related places where this code is rewritten or referenced so changes will be made there as well ?
  2. this is my first contribution so i dont know how to set up environment to test our changes so for that i am reading GettingStarted.md. I am a bit unsure about exactly what needs to be done rn.
  3. I am understanding what error is exactly. also are there any specific guidelines for wording error message ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants