-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[move 2024][alpha] Method syntax #13933
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
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.
Just a bunch of smaller things -- nothing major.
Can't wait for this to be enabled!
@@ -250,6 +251,7 @@ codes!( | |||
(NOTE: this may become an error in the future)", | |||
severity: Warning | |||
}, | |||
InvalidMethodCall: { msg: "invalid method style call", severity: BlockingError }, |
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.
Definitely prefer this over "invalid method call" and I think this conveys that this isn't an actual method call. One other option might be "invalid method-style function call" the addition of function helps disambiguate that this isn't an actual method you're calling I think.
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.
🚲 "invalid method-style invocation"
@@ -227,6 +247,7 @@ pub fn program( | |||
keyed | |||
}; | |||
|
|||
super::primitive_definers::determine(context.env, pre_compiled_lib, &module_map); |
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.
Not a gigantic name of determine
for this function since this validates them as opposed to determining them. Thoughts something more like validate
?
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 shall give it an even more cryptic name! (Seriously I think modules
is more in line with the rest of the compiler, but I'll add a comment)
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 great! This is amazing amazing amazing.
One little small change needed in an error message as far as I could see, but otherwise I'm happy :)
2 │ fun foo<T>(x: T) { | ||
│ - But 'T' was declared as a type parameter here | ||
3 │ use fun foo as T.foo; | ||
│ ^^^^^^^^^^^^^^^^^^^^^ Invalid 'use fun'. Cannot associate a function as a method a type parameter |
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.
This error message is a little wonky
Description
See 'Release Notes' for feature description.
This PR:
defines_primitive
annotation so that method style syntax can be used with primitive/builtin typesSome notes about implementation details
use a::m::f as g
introduces an implicituse fun a::m::f as a::m::S.g
in situations where the first argument ofa::m::f
isa::m::S
. This ensures that there isn't any weird precedence/shadowing betweenuse
anduse fun
in a given scope.x.foo()
, it always resolves to the same functiona::m::bar
, even if newpublic use fun
s are added elsewhere.ProgramInfo
into thenaming::ast::program
andtyping::ast::program
to properly resolveuse funs
(particularly with this implicit setup described above)TODO:
Follow up
let mut
andmut
variable modifiersTest Plan
How did you test the new or updated feature?
If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.
Type of Change (Check all that apply)
Release notes
Method style syntax has been added to Move 2024.alpha. This means functions can now be invoked with the syntax,
e.foo(arg1, arg2)
. Assuminge: a::m::S
(or&a::m::S
or&mut a::m::S
),e.foo(arg1, arg2)
will resolve toa::m::foo(e, arg1, arg2)
. Additionally, the compiler will borrowe
when necessary.For instances where the desired target function is not declared in the same module as the type (or is not declared with the desired name), a
use fun
alias can be used instead. For example,use b::n::bar as S.baz
will allowe.baz()
to resolve asb::n::bar(e)
. Apublic use fun
can be declared in the types defining module, allowing the alias to be used outside of the module.