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

Modified error message for the issue "Instance member cannot be used on type" #78043

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Niyatijain-9
Copy link

PR for #62909
Now the error message is more specific. Kindly review.

Now the error message is more specific.
@@ -1578,7 +1578,7 @@ ERROR(member_shadows_global_function,none,
(DeclNameRef, DescriptiveDeclKind, const ValueDecl *, DeclName))

ERROR(instance_member_use_on_type,none,
"instance member %1 cannot be used on type %0; "
"%1 non-static instance member cannot be called without an instance of type %0; "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all members are called, though. “Referenced” might be better

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the required changes. Kindly review.

Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the error in question is could_not_use_instance_member_on_type, not this one. They are similar, but this one targets a slightly different case: S.instanceMember.

I think we should explore the addition of a new tailored message for accesses on implicit self rather than trying to make the current one fit all targeted cases. This is what I proposed last time.

As far as I can tell, the message targets 2 cases:

struct S {
  func instanceF() {}
}

// 1.
let m = S.self
m.instanceF()

// 2.
extension S {
  static func staticF() {
    instanceF()
  }
}

The GitHub issue calls out case 2.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure about how to proceed about the changes, could you please guide me a bit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the message ID to search for the place where it is emitted. Take time to read through and examine the code around the emission site(s). Try to understand what is going on: which case is being handled, how the case is identified, what information is available about the diagnosed expression, and how you could use this data to form a condition for case 2 if we have not already.

If you prefer Xcode, adding some breakpoints and running the compiler with a Swift file containing the test case can be very helpful. Refer to this piece of documentation for LLDB advice.

If you have questions along the way, you are welcome to post them in the PR 🙂

changed "called" to referenced
@AnthonyLatsis
Copy link
Collaborator

I would like to encourage reviewers to read through a previous attempt at this: #63301.

@AnthonyLatsis AnthonyLatsis self-assigned this Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants