Skip to content

Fix #2888: Avoid caching supertypes of hk apps with provisional infos #2889

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

Merged
merged 3 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ object Flags {
/** A method that is known to have no default parameters */
final val NoDefaultParams = termFlag(61, "<no-default-param>")

/** A type symbol with provisional empty bounds */
final val Provisional = typeFlag(61, "<provisional>")

/** A denotation that is valid in all run-ids */
final val Permanent = commonFlag(62, "<permanent>")

Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3012,15 +3012,18 @@ object Types {

override def superType(implicit ctx: Context): Type = {
if (ctx.period != validSuper) {
validSuper = ctx.period
cachedSuper = tycon match {
case tp: HKTypeLambda => defn.AnyType
case tp: TypeVar if !tp.inst.exists =>
// supertype not stable, since underlying might change
return tp.underlying.applyIfParameterized(args)
case tp: TypeProxy => tp.superType.applyIfParameterized(args)
validSuper = Nowhere
tp.underlying.applyIfParameterized(args)
case tp: TypeProxy =>
if (tp.typeSymbol.is(Provisional)) validSuper = Nowhere
tp.superType.applyIfParameterized(args)
case _ => defn.AnyType
}
validSuper = ctx.period
}
cachedSuper
}
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ class Namer { typer: Typer =>
def abstracted(tp: Type): Type = HKTypeLambda.fromParams(tparamSyms, tp)
val dummyInfo = abstracted(TypeBounds.empty)
sym.info = dummyInfo
sym.setFlag(Provisional)
// Temporarily set info of defined type T to ` >: Nothing <: Any.
// This is done to avoid cyclic reference errors for F-bounds.
// This is subtle: `sym` has now an empty TypeBounds, but is not automatically
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i2888.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
trait Foo[A, CC[X] <: Foo[X, CC, CC[X]], C <: CC[A]] {

def cc: CC[A]

def foo: Unit = ()

def bar: Unit = cc.foo

}

object Main {
def main(args: Array[String]): Unit = ()
}