From 48f78cd66df9f6cd31201ba79b02891a99f1dfbe Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 24 Nov 2014 18:49:20 +0100 Subject: Simpler cycle detection Turns out that the last commit was a red herring. None of the hoops it jumped though was necessary. Instead there was a bug in isRef which caused `&` to erroneously compute T & Int as Int. The bug was that we always approximated alias types by their high bound. But in the present case, this leads to errors because U gets 'bounds >: Nothing <: Any', but it was still an alias type (i.e. its Deferred flag is not set). The fix dereferences aliases only if their info is a TypeAlias. --- src/dotty/tools/dotc/typer/Namer.scala | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'src/dotty/tools/dotc/typer/Namer.scala') diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 7490e88e9..86376356c 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -673,7 +673,17 @@ class Namer { typer: Typer => def typeDefSig(tdef: TypeDef, sym: Symbol)(implicit ctx: Context): Type = { completeParams(tdef.tparams) - setDummyInfo(sym) + sym.info = TypeBounds.empty + // 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 + // made an abstract type. If it had been made an abstract type, it would count as an + // abstract type of its enclosing class, which might make that class an invalid + // prefix. I verified this would lead to an error when compiling io.ClassPath. + // A distilled version is in pos/prefix.scala. + // + // The scheme critically relies on an implementation detail of isRef, which + // inspects a TypeRef's info, instead of simply dealiasing alias types. val tparamSyms = tdef.tparams map symbolOfTree val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree] val toParameterize = tparamSyms.nonEmpty && !isDerived @@ -690,21 +700,4 @@ class Namer { typer: Typer => sym.info = NoCompleter checkNonCyclic(sym, unsafeInfo, reportErrors = true) } - - /** Temporarily set info of defined type T to - * - * T >: dummyLo <: dummyHi - * type dummyLo, dummyHi - * - * This is done to avoid cyclic reference errors for F-bounds. - * The type is intentionally chosen so that it cannot possibly be - * elided when taking a union or intersection. - */ - private def setDummyInfo(sym: Symbol)(implicit ctx: Context): Unit = { - def dummyBound(name: TypeName) = - ctx.newSymbol(sym.owner, name, Synthetic | Deferred, TypeBounds.empty) - val dummyLo = dummyBound(tpnme.DummyLo) - val dummyHi = dummyBound(tpnme.DummyHi) - sym.info = TypeBounds(TypeRef(NoPrefix, dummyLo), TypeRef(NoPrefix, dummyHi)) - } } \ No newline at end of file -- cgit v1.2.3