-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Imports from unstable prefixes should not be allowed #10295
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
Comments
We need this in some form to be able to support imports for contextual abstractions. This feature allows us to import the contents of the context parameter without naming it. trait M:
type X
object X:
def foo(): X
def m(using m: M): m.type = m
def doSomething(body: M ?=> Unit) = ...
doSomething {
val x: m.X = m.X.foo()
...
}
// or with an import
doSomething {
import m._ // Consice and clear import of the same stable path `m`
val x: X = X.foo()
...
}
// without this feature we would need an extra line in each call site
doSomething {
// not ideal
val myM = m // or summon[M]
import myM._
val x: X = X.foo()
}
// or
doSomething { (m: M) ?=> // defeats the purpose of context functions
import m._
val x: X = X.foo()
}
def f(using M)(x: m.X) = m.X.foo() |
@nicolasstucki Can |
Note that this is used in reflection API as follows:
It's also possible to use
To an extent, I'm fine with this being an idiom. It'd feel less like a hack if |
We also do the same with |
Also for |
The use case for contextual abstractions is still supported if the function returning an implicit parameter is declared `inline`.
The use case for contextual abstractions is still supported if the function returning an implicit parameter is declared `inline`.
Fix #10295: Require import qualifiers to be idempotent
I don't think this is intentionally allowed, it only works when the def returns a singleton type:
(if one really wants to pretend a prefix is stable, there's an
@uncheckedStable
annotation, though it's implemented by Scala 2 but not Dotty)The text was updated successfully, but these errors were encountered: