FEAT: Func implementation must come after all @overload declarations#443
FEAT: Func implementation must come after all @overload declarations#443iwakitakuma33 wants to merge 4 commits intofacebook:mainfrom
Conversation
|
Hi @iwakitakuma33! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Thank you!!! I'll let @rchen152 review this. Just FYI #430 included both this issue and another (likely more difficult to implement) one |
|
@kinto0 This is my first time contributing to this repository, so I started small. |
|
Thanks! Could you please add an integration test case in this file? |
|
@yangdanny97 I did fix to show error if concrete function has overload. |
a61647f to
5c8b0d5
Compare
rchen152
left a comment
There was a problem hiding this comment.
Thank you for the PR! It would be great if the new error messages could be reported instead of the confusing "Overloaded function must have an implementation" messages, rather than both messages being shown. I left in-line comments with suggestions for how to do that.
pyrefly/lib/alt/function.rs
Outdated
| def.name.range, | ||
| ErrorKind::InvalidOverload, | ||
| None, | ||
| "@overload decorator should not be used on function implementations.".to_owned(), |
There was a problem hiding this comment.
Similar to my other comment - this is a good error message, but we should report either this error or "Overloaded function must have an implementation," not both.
If you add a new stub_or_impl field to DecoratedFunction (
if !skip_implementation {
if def.stub_or_impl == FunctionStubOrImpl::Impl {
// report "@overload decorator should not be used on function implementations."
else {
// report "Overloaded function must have an implementation"
}
}
pyrefly/lib/alt/function.rs
Outdated
| implementation_range, | ||
| ErrorKind::InvalidOverload, | ||
| None, | ||
| "Function implementation must come after all @overload declarations. ".to_owned(), |
There was a problem hiding this comment.
I like this error message, but I think it's confusing that this error and "Overloaded function must have an implementation" are both reported; we should report one or the other.
What I'd suggest doing is: when we encounter an @overload-decorated signature with no successors, we loop through the predecessors to see if there's an implementation among them. If there is, then we report this error rather than the "Overloaded function must have an implementation" error. Here's an example of how to loop through predecessors:
pyrefly/pyrefly/lib/alt/function.rs
Lines 485 to 502 in 4a08127
There was a problem hiding this comment.
@rchen152
Thank you for your feedback. I have made revisions based on your comments.
I have also added tests.
When I revised the code to prevent the message “Overloaded function needs at least two signatures” from appearing unnecessarily, evaluating get_idx in the successor direction caused lazy evaluation to occur, causing tests other than overload to fail. Therefore, in this PR,I have limited the scope to cases where successor.is_none is true.
There was a problem hiding this comment.
Sorry for the delay! I somehow missed a bunch of GitHub notifications this past week. I'll review this tomorrow.
23f2f45 to
a697a25
Compare
|
@rchen152 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
Thanks @iwakitakuma33! |
#430