Explicit context arguments #465
Replies: 7 comments 24 replies
-
|
This reuses the syntax for normal function calls as if context parameter was not present and it was a regular function parameter. This will be confusing imo. |
Beta Was this translation helpful? Give feedback.
-
|
Previously, specifying the name of a contextual parameter meant “I WILL explicitly use this name in the implementation”, otherwise “_” was specified. Now it is proposed to break this convention and, whenever possible, always name contextual parameters for the sole purpose of resolving conflicts if they happen to arise somewhere. Ok, this may be useful, but I would like to hope that as the idea develops, this naming convention will not become strictly mandatory. |
Beta Was this translation helpful? Give feedback.
-
|
... in addition, previously the name of the contextual parameter was not part of the call contract for the function, and we could write constructions like this: interface I {
context(_: Int)
fun a() {
}
}
class C : I {
override context(a: Int) fun a() { println(a) }
}
Now, as I understand it, it is proposed to consider such constructions invalid? |
Beta Was this translation helpful? Give feedback.
-
|
This finally makes it so that naming context parameters in abstract functions is useful. Nice! |
Beta Was this translation helpful? Give feedback.
-
|
I want to point out that this makes duplicate types in context parameters useable. I believe the decision was made before that subtyping between contexts would be allowed because it'd ultimately error when in call resolution, or both parameters would be fulfilled by the same argument. Now that's no longer the case: Note that references to contextual functions are disallowed, so I'm pretty sure you could've never written the code above without reflection, but now you can. |
Beta Was this translation helpful? Give feedback.
-
|
Overall a good idea, but I think that handling of "conflicting" overloads where a parameter with the same name is once a context parameter, in another case a regular one can use some more thought (e.g. First of all, these patterns should be avoided, but in such context (maybe to support compatibility/transition to context parameters), it is not clear why preferring one over the other is legitimate (esp. why would the context one be more specific?). More importantly is to consider what the rule does to existing code. Existing code that calls |
Beta Was this translation helpful? Give feedback.
-
|
Based on the new availability of explicit context arguments, we have decided to update the way "most specific candidate selection" treats context parameters, as described in this commit. In short:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This is an issue to discuss explicit context arguments. The current full text of the proposal can be found here.
In this document, we propose an extension to calls to functions with context parameters, so that context arguments can be given explicitly.
Beta Was this translation helpful? Give feedback.
All reactions