-
Notifications
You must be signed in to change notification settings - Fork 21
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
Possible Regression in 2.12.0-RC1 inferencing type annotation #9931
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9931?orig=1 |
@SethTisue said: trait Compute[A] {
type Start
val start: Compute[Start]
}
object Test {
def foo[A](c: Compute[A]): Unit =
c match {
case c: Compute[A] =>
new Compute[A] {
type Start = c.Start
val start = c.start
}
}
} Perhaps it can be minimized further, but I got stuck here. In particular, I did not succeed in getting rid of the pattern match. This almost certainly has to do with the changes in type inference for valdefs that came in scala/scala#5141. As evidence, compiling with 2.12.0-M5 makes the error go away, as does compiling with -Xsource:2.11. |
@SethTisue said: - case c: Compute[A] =>
+ case d: Compute[A] =>
+ val c = d which certainly makes it seem like it's a pattern-matcher issue. |
@SethTisue said (edited on Sep 21, 2016 10:21:46 PM UTC): trait Compute[A] {
type Start
val start: Compute[Start]
}
object Test {
def foo(c: Any): Unit =
c match {
case c: Compute[a] =>
new Compute[a] {
type Start = c.Start
val start = c.start
}
}
} It's not that interestingly different, because in both versions, the type parameter on Compute isn't actually used anywhere. Regardless, as far as I can tell, you do need to have a type parameter in order to trigger the issue. (Throwing away the type member instead makes the issue vanish, too.) |
@SethTisue said: |
@adriaanm said: |
@SethTisue said:
With "def" you get the error in both 2.11.8 and 2.12.0-RC1. Dotty accepts both the "def" and "val" versions, so this isn't a case where we can say "we're like Dotty now". |
@adriaanm said: This indicates to me it used to compile due to a latent bug in the old handling of fields. It still doesn't explain why it compiles on Dotty. Still investigating that avenue. ➜ scala git:(2.12.0) ~/scala/scala-2.11.8/bin/scalac /tmp/Eval.scala -Xprint:typer -Ydebug
[...]
/tmp/Eval.scala:7: error: overriding value start in class Compute of type scala.this.Function0[<empty>.this.Eval[$anon.this.Start]];
value start has incompatible type;
found : => scala.this.Function0[<empty>.this.Eval[x2.Start]]
required: => scala.this.Function0[<empty>.this.Eval[Compute.this.Start]]
val start = c.start
^
one error found sealed abstract class Eval[+A] {
def flatMap[B](f: A => Eval[B]): Eval[B] =
this match {
case c: Eval.Compute[A] =>
new Eval.Compute[B] {
type Start = c.Start
val start = c.start
}
}
}
object Eval {
sealed abstract class Compute[A] extends Eval[A] {
type Start
val start: () => Eval[Start]
}
} |
@adriaanm said: |
Alistair Johnson (alistair.johnson-at-johnsonusm.com) said: So just doing some house cleaning: I have added a workaround in this cats PR - could someone cast a quick eye that the fix is the best for now, please? Then I can leave this for a while... Thx - Alistair |
@SethTisue said: |
Alistair Johnson (alistair.johnson-at-johnsonusm.com) said: |
This is a cache invalidation bug in
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 97aea13c3b..ff1fe95311 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -2249 +2249 @@ trait Types
- if (normalized eq null)
+ if (normalized eq null) {
@@ -2250,0 +2251,3 @@ trait Types
+ } else {
+ assert(normalized =:= normalizeImpl, (this, normalized, normalizeImpl))
+ }
@@ -2251,0 +2255 @@ trait Types
+ We have some code that tried to invalidate caches after substitution, but this example is a step ahead. Maybe we need to rethink this, perhaps we could disable these caches in symbols and typerefs that are local, which is where all the problems arise. |
WIP for disabling caching for types formed over local symbols: https://github.com/scala/scala/compare/2.12.x...retronym:ticket/9931?expand=1 |
I've moved this from the 2.12.5 milestone to Backlog, but also: bump!, in case anyone wants to resume work on this. |
Minimization works in 2.13.0, test in PR but I did not investigate. |
@som-snytt thanks for all the triage just lately ❤️ |
I'm just the right age for triage. I was looking for an old ticket and found others instead. |
This is documented in typelevel/cats#1377 and we are not sure if this a known change/improvement or bug.
Compiling file Eval.scala
Compile errror:
Trivial fix:
Apologies if this is a false alarm, we do not mind just applying the fix but as Erik says in the issue, it makes sense to let you guys know just in case.
The text was updated successfully, but these errors were encountered: