Skip to content

Commit db950e5

Browse files
committed
Merge pull request #61 from odersky/fixes-t00xx
Fixes t00xx
2 parents 6e7dd1b + 6629101 commit db950e5

File tree

8 files changed

+45
-10
lines changed

8 files changed

+45
-10
lines changed

src/dotty/tools/dotc/core/Flags.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ object Flags {
467467
final val ExpandedTypeParam = allOf(ExpandedName, TypeParam)
468468

469469
/** A parameter or parameter accessor */
470-
final val ParamOrAccessor = Param | Accessor
470+
final val ParamOrAccessor = Param | ParamAccessor
471471

472472
/** A covariant type parameter instance */
473473
final val LocalCovariant = allOf(Local, Covariant)

src/dotty/tools/dotc/core/SymDenotations.scala

+8-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,14 @@ object SymDenotations {
145145
if (myFlags is Touched) throw new CyclicReference(this)
146146
myFlags |= Touched
147147

148-
completions.println(s"completing ${this.debugString}")
149-
completer.complete(this)
150-
completions.println(s"completed ${this.debugString}")
148+
// completions.println(s"completing ${this.debugString}")
149+
try completer.complete(this)
150+
catch {
151+
case ex: CyclicReference =>
152+
completions.println(s"error while completing ${this.debugString}")
153+
throw ex
154+
}
155+
// completions.println(s"completed ${this.debugString}")
151156
}
152157

153158
protected[dotc] final def info_=(tp: Type) = {

src/dotty/tools/dotc/typer/Checking.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ trait Checking extends NoChecking {
4646
}
4747

4848
/** Check that type arguments `args` conform to corresponding bounds in `poly` */
49-
override def checkBounds(args: List[tpd.Tree], poly: PolyType, pos: Position)(implicit ctx: Context): Unit =
49+
override def checkBounds(args: List[tpd.Tree], poly: PolyType, pos: Position)(implicit ctx: Context): Unit = {
50+
val argTypes = args.tpes
51+
def substituted(tp: Type) = tp.substParams(poly, argTypes)
5052
for ((arg, bounds) <- args zip poly.paramBounds) {
5153
def notConforms(which: String, bound: Type) =
5254
ctx.error(i"Type argument ${arg.tpe} does not conform to $which bound $bound", arg.pos)
53-
if (!(arg.tpe <:< bounds.hi)) notConforms("upper", bounds.hi)
55+
if (!(arg.tpe <:< substituted(bounds.hi))) notConforms("upper", bounds.hi)
5456
if (!(bounds.lo <:< arg.tpe)) notConforms("lower", bounds.lo)
5557
}
58+
}
5659

5760
/** Check that type `tp` is stable. */
5861
override def checkStable(tp: Type, pos: Position)(implicit ctx: Context): Unit =

src/dotty/tools/dotc/typer/Namer.scala

+11-1
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,18 @@ class Namer { typer: Typer =>
216216
checkNoConflict(name)
217217
val deferred = if (lacksDefinition(tree)) Deferred else EmptyFlags
218218
val method = if (tree.isInstanceOf[DefDef]) Method else EmptyFlags
219+
220+
// to complete a constructor, move one context further out -- this
221+
// is the context enclosing the class. Note that the context in which a
222+
// constructor is recorded and the context in which it is completed are
223+
// different: The former must have the class as owner (because the
224+
// constructor is owned by the class), the latter must not (because
225+
// constructor parameters are interpreted as if they are outside the class).
226+
val cctx = if (tree.name == nme.CONSTRUCTOR) ctx.outer else ctx
227+
219228
record(ctx.newSymbol(
220229
ctx.owner, name, tree.mods.flags | deferred | method,
221-
adjustIfModule(new Completer(tree), tree),
230+
adjustIfModule(new Completer(tree)(cctx), tree),
222231
privateWithinClass(tree.mods), tree.pos))
223232
case tree: Import =>
224233
record(ctx.newSymbol(
@@ -614,6 +623,7 @@ class Namer { typer: Typer =>
614623

615624
def typeDefSig(tdef: TypeDef, sym: Symbol)(implicit ctx: Context): Type = {
616625
completeParams(tdef.tparams)
626+
sym.info = TypeBounds.empty // avoid cyclic reference errors for F-bounds
617627
val tparamSyms = tdef.tparams map symbolOfTree
618628
val rhsType = typedAheadType(tdef.rhs).tpe
619629

src/dotty/tools/dotc/typer/Typer.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
701701
val TypeBoundsTree(lo, hi) = desugar.typeBoundsTree(tree)
702702
val lo1 = typed(lo)
703703
val hi1 = typed(hi)
704-
if (!(lo1.tpe <:< hi1.tpe))
705-
ctx.error(i"lower bound ${lo1.tpe} does not conform to upper bound ${hi1.tpe}", tree.pos)
704+
// need to do in later phase, as this might cause a cyclic reference error. See pos/t0039.scala
705+
// if (!(lo1.tpe <:< hi1.tpe))
706+
// ctx.error(i"lower bound ${lo1.tpe} does not conform to upper bound ${hi1.tpe}", tree.pos)
706707
assignType(cpy.TypeBoundsTree(tree, lo1, hi1), lo1, hi1)
707708
}
708709

@@ -788,7 +789,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
788789
val constr1 = typed(constr).asInstanceOf[DefDef]
789790
val parents1 = ensureConstrCall(ensureFirstIsClass(
790791
parents mapconserve typedParent, cdef.pos.toSynthetic))
791-
val self1 = typed(self).asInstanceOf[ValDef]
792+
val self1 = typed(self)(ctx.outer).asInstanceOf[ValDef] // outer context where class memebers are not visible
792793
val localDummy = ctx.newLocalDummy(cls, impl.pos)
793794
val body1 = typedStats(body, localDummy)(inClassContext(self1.symbol))
794795
checkNoDoubleDefs(cls)

tests/new/t0039.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
abstract class Extensible[A, This <: Extensible[A, This]](x: A, xs: This) { self: This =>
2+
def mkObj(x: A, xs: This): This;
3+
}
4+
class Fixed[A](x: A, xs: Fixed[A]) extends Extensible[A, Fixed[A]](x, xs) {
5+
def mkObj(x: A, xs: Fixed[A]) = new Fixed(x, xs);
6+
}

tests/pos/t0002.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object main {
2+
def main(args: Array[String]) = {
3+
val b = true;
4+
while (b == true) { }
5+
}
6+
}

tests/pos/t0054.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class A {
2+
case class B(x: C) extends A { val z: A.this.C = x }
3+
class C {}
4+
}

0 commit comments

Comments
 (0)