-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Compiler-v2] fix receiver call with index notation #15239
Conversation
⏱️ 2h 18m total CI duration on this PR
|
"receiver call needs to have at least one parameter" | ||
); | ||
let receiver_call_opt = self.get_receiver_function(&arg_types[0], name); | ||
if let (Some(receiver_call), Exp_::ExpDotted(dotted)) = |
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.
Can we add a test case where receiver_call_opt
would be None
? When I tried this out, we get a "unknown receiver function" error, but might be good to have a test to prevent any regressions.
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.
Added a test case to calls_index_errors.move
.
174da20
to
e7924fb
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.
Do we have a test somewhere for x[i].call()
with mutable self parameter?
I have tested this case but will add a test case |
e7924fb
to
cf46f9c
Compare
@vineethk @brmataptos, I need another round review for handling |
translated_args[0] = first_arg.into_exp(); | ||
} | ||
} else if let Exp_::Index(target, index) = &args[0].value { | ||
// special case for the receiver call S[x].fun(&...) |
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.
// special case for the receiver call S[x].fun(&...) | |
// special case for the receiver call `S[x].fun(&...)` and `S[x].fun(&mut...)` |
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.
done
let receiver_call_opt = self.get_receiver_function(&arg_types[0], name); | ||
if let Some(receiver_call) = receiver_call_opt { | ||
if let Exp_::ExpDotted(dotted) = &args[0].value { | ||
// special case for the receiver call S[x].f.fun(&mut...) |
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.
Would be useful to add some note on why these special cases are needed (e.g., we resolve X before doing Y translation), for future refactors/bug fixes.
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.
done
} | ||
|
||
fun foo_2(account: address, w: W) acquires W { | ||
W[account].merge(w) |
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.
Could we add the following test case (or similar) that tests:
- Non-mut ref receiver over resource indexing
- Resource indexing on a generic type that goes through the newly added translation.
struct Wrapper<T> has drop, key, store, copy {
inner: T
}
fun unwrap<T>(self: &Wrapper<T>): T {
self.inner
}
fun dispatch<T>(account: address): T acquires Wrapper {
Wrapper<T>[account].unwrap()
}
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.
done
cf46f9c
to
5ad7598
Compare
5ad7598
to
447fc98
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
This PR fixes
A[...].foo(&)
orA[...].foo(&mut)
, translateA[...]
into a reference directly so that it behaves like(&A[...]).foo(...)
or(&mut A[...]).foo(...)
.Close #15224
How Has This Been Tested?
Key Areas to Review
Type of Change
Which Components or Systems Does This Change Impact?
Checklist