-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SR-13976: Improve compiler error message: "partial application of ‘mutating’ method is not allowed" #35466
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
Conversation
Thanks for the PR. 🙂 Minor comment: Generally we try to implement the test and change in the same commit (or alternately, add a failing test marked as XFAIL in the first commit, and implement the fix and remove the XFAIL in the second commit). That way, bisection becomes easier. For this particular case, it's not a big deal though, as we can squash the changes at the end. |
I can squash the commits when I change from calling -> using |
This is what I have come up with! What do you folks think before I go further? @varungandhi-apple @LucianoPAlmeida @xedin
Here is some of the test output from
|
I like it! I'd also suggest to add a note - |
And one more thing - a better check would be to account for defaultable parameters as well, so if there are 0 parameters or all of the parameters are defaultable - fix-it. |
I thought that was the purpose of the |
Ah, right, sorry I missed that one, then the only viable thing is related to default parameters and we should be good to go! |
I cannot figure out how to check for that. Is there a part of the docs I should be looking at specifically? |
If I remember correctly parameter list consists of |
An example you can look at :) https://github.com/apple/swift/blob/19a4df331c3de41dac1b2d069cbda863ed0f24e5/lib/Sema/CSSimplify.cpp#L3437-L3446 |
Sorry for the delay folks. The example posted earlier has some functions that aren't available in the file, as to not add more imports I went down the
Btw is it ok to force push over this branch? |
Yeah, it's fine to force push. |
@abdulajet There is an |
I would suggest using |
Also, please don't apologize about delays or similar. 😄 It's totally okay. You're doing this in your free time and we are thankful for your contributions, at whatever pace works for you. |
Thanks for all the help!
Ill get the tests done then push this up. |
Sounds great, thank you! |
I think you mean |
aha yes i 100% do. cheers |
Sorry if this is being nitpicking but I think that |
Works either way, I think it's a matter of personal preference. |
I have an issue where the conditions for the fixit are being applied where they shouldn't:
Is there someone I can see an example of a check for if the function is being called? Not sure i can see anything on the public interface of For @xedin you mentioned
in the initial discussion. Should this be in its own test file? Thanks all! |
Shouldn't the logic which detects that it's a partial application already handle that?
I think you can add new tests to |
Oh yeah, of course! In that case, I am not sure why the diag is being called for this test Here is an example of the failing test from
|
@abdulajet Since |
Cool, ill look into that. Thanks |
@xedin I have had a look around, the path I was going down was trying to see if the function was marked with a class descriptor and returning false out of the diagnostic. Would this a good solution (if it is, can I have a hand in checking the function descriptors. Thanks again |
@abdulajet The way diagnostics are currently implemented in the solver is two-fold - there is a "ConstraintFix" and that has a "FailureDiagnostic" attached to that. What you want to do here is to prevent a fix ( |
Amazing! Will take a look, thanks. |
Given that the SR is only about the terminology, I think this would be fine :) |
I think using |
ok to revert back to just changing the text of the diagnostic then 2 new SRs. One for the diagnostic being called incorrectly and a dependent one that adds the fix it? |
Sounds good to me =] |
Thank you! |
Sure thing! Will do it this weekend |
Did we want to leave it as "calling" or change to "referencing" |
From what I see here #35466 (comment) we agreed on |
Agree with @LucianoPAlmeida here, "referencing" seems more appropriate here. |
@LucianoPAlmeida updated to use "reference" and added some comments to name_lookup.swift for the linked SRs. Let me know if they are better placed elsewhere |
@swift-ci Please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to go to me!
@abdulajet there is one missing test to adjust |
"'mutating' method|" | ||
"'super.init' initializer chain|" | ||
"'self.init' initializer delegation|" | ||
"'super' instance method with metatype base" | ||
"}0 is not allowed", | ||
"}0 without an argument list", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that we agreed to use as function value
instead of without an argument list
? Also nit on the grammar - diagnostics shouldn't include articles "a" or "an" in the text because they make a diagnostic longer without adding any information (see https://github.com/apple/swift/blob/main/docs/Diagnostics.md).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, that's true, I just miss that 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad. referencing x as a function value coming up
@swift-ci Please smoke test |
"'mutating' method|" | ||
"'super.init' initializer chain|" | ||
"'self.init' initializer delegation|" | ||
"'super' instance method with metatype base" | ||
"}0 is not allowed; calling the function has undefined behavior and will " | ||
"}0 as function value; calling the function has undefined behavior and will " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot build swift locally at the moment, while I fix that so I can run the test suite locally. Does the second clause here make sense? "cannot reference x as function value calling the function has undefined..."
I think so since is error/warning will be in the context of a function I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it makes sense, second part is a clarification on why it can't be used as a function value - because calling it is UB.
…tating’ method is not allowed”
@@ -6,31 +6,31 @@ struct Foo { | |||
mutating func boom() {} | |||
} | |||
|
|||
let x = Foo.boom // expected-warning{{partial application of 'mutating' method}} | |||
let x = Foo.boom // expected-warning{{cannot reference 'mutating' method as function value; calling the function has undefined behavior and will be an error in future Swift versions}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why this test was working on main before? the warnings for swift 4 should have always had the second clause.
But alas, run the tests locally and fixed the CI issues
@swift-ci please test |
Looks like it's time to land this! Thank you, @abdulajet and @LucianoPAlmeida! |
thanks all for the help! |
As mentioned on the Jira ticket, partial application is not a well-known term so I have reworded the error messages with a suggested phrase to help people diagnose the issue easier.
Based on the diagnostics definition file there were 4 different combinations that I saw that used the error, below is the wording changes i made:
The first commit has the change, second commit has the test updates.
Resolves SR-13976. cc @varungandhi-apple