-
Notifications
You must be signed in to change notification settings - Fork 119
feat: add support for implicit arguments #5517
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
a9c3cdb to
037c74d
Compare
037c74d to
bd9076b
Compare
|
Latest commits lock good @christoph-dfinity! |
…#5526) * track whether the argument was parenthesized on a call expression * don't flatten parenthesized tuple arguments for implicit search * add repro * don't insert holes twice --------- Co-authored-by: Claudio Russo <[email protected]>
test/fail/implicit-bug.mo
Outdated
|
|
||
| let t : Nat = 0; | ||
|
|
||
| // let _ = map.get(t); |
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.
there is no bug anymore, right?
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 think not. Let me rewrite the test.
* implicit-bug to implicit-map test * diamond resolution fail test + covariant and contravariant implicit reoslution * cleanup
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.
LGTM!
Add support for
implicitargument declarations (feat: add support for implicit arguments #5517).Function and class parameters can be declared implicit using a specially named type of the form:
implicit : <typ>(implicit named or anonymous parameter).implicit : (<id> : <typ>)(implicit parameter matching name<id>and<typ>).implicit : (_ : <typ>)(implicit parameter matching<typ>under any name).This is just a special case of a named type in Motoko with special name "implicit".
The arguments corresponding to implicit parameters can be omitted at call sites, provided the compiler can unambiguously resolve using a declaration of the given name and matching type, in either the current scope or the fields of a module in the current scope. By default, the name is determined by the parameter declared
implicitbut can be specified to be another name,<id>, using the second form ofimplicittype annotation above (seePair.toTextbelow for an example).An unnamed parameter or a named parameter declared with the third form of anonymous declaration matches any name in the context that has a matching type only.
Any candidate from the current scope is preferred over candidates from nested scopes.
In the rare case that a function has more than one implicit parameter, either all arguments must be specified or all implicit arguments omitted.
Functions that require two implicits of the same (external)
namecan declare them with different argument names (to distinguish their implementations), and common (external) names, using a nested name.Example: