-
Notifications
You must be signed in to change notification settings - Fork 103
FEAT: Func implementation must come after all @overload declarations #443
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
base: main
Are you sure you want to change the base?
FEAT: Func implementation must come after all @overload declarations #443
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
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 (
pub struct 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
fn step_overload_pred(&self, pred: &mut Option<Idx<Key>>) -> Option<Arc<DecoratedFunction>> { | |
let pred_idx = (*pred)?; | |
let mut b = self.bindings().get(pred_idx); | |
while let Binding::Forward(k) = b { | |
b = self.bindings().get(*k); | |
} | |
if let Binding::Function(idx, pred_, _) = b { | |
let def = self.get_idx(*idx); | |
if def.metadata.flags.is_overload { | |
*pred = *pred_; | |
Some(def) | |
} else { | |
None | |
} | |
} else { | |
None | |
} | |
} |
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.
@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.
23f2f45
to
a697a25
Compare
#430