Skip to content

Commit da23062

Browse files
committed
Address comments.
1 parent 867c538 commit da23062

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

content/multi-source-extension-overloads.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,37 @@ For the same reason, we do not propose to change regular calls of methods that h
157157

158158
### Specification
159159

160-
From the [specification of extension methods](https://docs.scala-lang.org/scala3/reference/contextual/extension-methods.html#translation-of-calls-to-extension-methods), we amend step 1. of "The precise rules for resolving a selection to an extension method are as follows."
160+
We make two changes to the [specification of extension methods](https://docs.scala-lang.org/scala3/reference/contextual/extension-methods.html).
161+
162+
In the section [Translation of Extension Methods](https://docs.scala-lang.org/scala3/reference/contextual/extension-methods.html#translation-of-extension-methods), we make it clearer that the "desugared" version of the call site may require an explicit qualifier.
163+
This is not strictly a novelty of this SIP, since it could already happen with `given`s and implicit scopes, but this SIP adds one more case where this can happen.
164+
165+
Previously:
166+
167+
> So, the definition of circumference above translates to the following method, and can also be invoked as such:
168+
>
169+
> `<extension> def circumference(c: Circle): Double = c.radius * math.Pi * 2`
170+
>
171+
> `assert(circle.circumference == circumference(circle))`
172+
173+
With this SIP:
174+
175+
> So, the definition of circumference above translates to the following method, and can also be invoked as such:
176+
>
177+
> `<extension> def circumference(c: Circle): Double = c.radius * math.Pi * 2`
178+
>
179+
> `assert(circle.circumference == circumference(circle))`
180+
>
181+
> or
182+
>
183+
> `assert(circle.circumference == qualifierPath.circumference(circle))`
184+
>
185+
> for some `qualifierPath` in which `circumference` is actually declared.
186+
> Explicit qualifiers may be required when the extension method is resolved through `given` instances, implicit scopes, or disambiguated from several imports.
187+
188+
---
189+
190+
In the section [Translation of Calls to Extension Methods](https://docs.scala-lang.org/scala3/reference/contextual/extension-methods.html#translation-of-calls-to-extension-methods), we amend step 1. of "The precise rules for resolving a selection to an extension method are as follows."
161191

162192
Previously:
163193

@@ -180,16 +210,21 @@ With this SIP:
180210
The proposal only alters situations where the previous specification would reject the program with an ambiguous import.
181211
Therefore, we expect it to be backward source compatible.
182212

183-
The resolved calls could previously be spelled out by hand (with fully-qualified names), so binary and TASTy compatibility are not affected.
213+
The resolved calls could previously be spelled out by hand (with fully-qualified names), so binary compatibility and TASTy compatibility are not affected.
214+
215+
### Other concerns
216+
217+
With this SIP, some calls that would be reported as *ambiguous* in their "normal" form can actually be written without ambiguity if used as extensions.
218+
That may be confusing to some users.
219+
Although specific error messages are not specified and therefore outside the SIP scope, we encourage the compiler implementation to enhance the "ambiguous" error message to address this confusion.
220+
If some or all of the involved ambiguous targets are `extension` methods, the compiler should point out that the call might be resolved unambiguously if used as an extension.
184221

185222
## Alternatives
186223

187224
A number of alternatives were mentioned in [the Contributors thread](https://contributors.scala-lang.org/t/change-shadowing-mechanism-of-extension-methods-for-on-par-implicit-class-behavior/5831), but none that passed the bar of "we think this is actually implementable".
188225

189226
## Related work
190227

191-
This section should list prior work related to the proposal, notably:
192-
193228
- [Contributors thread acting as de facto Pre-SIP](https://contributors.scala-lang.org/t/change-shadowing-mechanism-of-extension-methods-for-on-par-implicit-class-behavior/5831)
194229
- [Pull Request in dotty](https://github.com/lampepfl/dotty/pull/17050) to support it under an experimental import
195230

0 commit comments

Comments
 (0)