-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Drop requirement that self types are closed #16648
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
If someone manages to revive t7933.scala that would be very helpful. It's in pending/run. Here is the code: mport scala.tools.nsc.interpreter.IMain
object Test extends App {
val engine = new IMain.Factory getScriptEngine()
engine.asInstanceOf[IMain].settings.usejavacp.value = true
val res2 = engine.asInstanceOf[javax.script.Compilable]
res2 compile "8" eval()
val res5 = res2 compile """println("hello") ; 8"""
res5 eval()
res5 eval()
} |
I guess the intention is to protect against situations like this: trait X { self: Y =>
val a = g() // what's the type of this val!?
f(a)
}
trait Y { self: Z =>
type B = A
def f(a: B): Unit = ()
def g(): A = ???
}
trait Z {
type A
} When computing the type of |
@sjrd Ah yes, I think that was the crucial counter-example. But we are already dealing with it gracefully:
So I think we don't need a separate test in RefChecks (which would come later anyway). |
58d68ae
to
60cb909
Compare
scala#702 introduced a requirement that self types are closed. This means > If trait X has self type S and C is a class symbol of S, then S also conforms to the self type of C. An example that violates this requirement is ```scala trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y trait Y { self: Z => } trait Z ``` But it's no longer clear what the requirement should achieve. If we let the example above typecheck and try to implement X with something like ```scala class C extends X, Y ``` we would at that point get an error saying that `C` does not conform to the self type Z of Y. So it would have to be ```scala class C extends X, Y, Z ``` and this one looks fine. The original change in scala#702 was made to avoid a crash in pending/run/t7933.scala. Unfortunately, we cannot reproduce this anymore since it depends on nsc.interpreter, which is no longer part of Scala 2.13. Since we are no longer sure what the restriction should achieve I think it's better to drop it for now. If people discover problems with code that uses "open" self types, we can try to fix those problems, and if that does not work, would fallback re-instituting the restriction. It's not ideal, but I don't see another way.
} | ||
|
||
trait Z[A] extends X { | ||
self: Z[A] => // comment this to compile successfully |
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.
The comments in this pos
file are not accurate. They say there's an error but clearly there isn't.
@@ -0,0 +1,8 @@ | |||
|
|||
trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y |
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.
Same here. There is no error anymore.
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.
True. But we do leave the old errors in anyway if a neg test gets moved to pos as a documentation what went wrong before. That's done for many other pos tests as well.
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.
Ah OK. I did not know that. All good, then.
#702 introduced a requirement that self types are closed. This means
An example that violates this requirement is
But it's no longer clear what the requirement should achieve. If we let the example above typecheck and try to implement X with something like
we would at that point get an error saying that
C
does not conform to the self type Z of Y. So it would have to beand this one looks fine.
The original change in #702 was made to avoid a crash in pending/run/t7933.scala. Unfortunately, we cannot reproduce this anymore since it depends on nsc.interpreter, which is no longer part of Scala 2.13.
Since we are no longer sure what the restriction should achieve I think it's better to drop it for now. If people discover problems with code that uses "open" self types, we can try to fix those problems, and if that does not work, would fallback re-instituting the restriction. It's not ideal, but I don't see another way.
Fixes #16407