Skip to content

Commit 0d6cdd9

Browse files
committed
Reorganize tests to account for new typing of projection
Tests with failed projections are moved to pos-scala2, which was renamed from pos-special. Files in pos-scala2 are compiled with -language:Scala2 option.
1 parent a9312e9 commit 0d6cdd9

File tree

18 files changed

+111
-45
lines changed

18 files changed

+111
-45
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
394394
/** The realizability status of given type `tp`*/
395395
def realizability(tp: Type): Realizability = tp.dealias match {
396396
case tp: TermRef =>
397-
if (tp.symbol.isRealizable) Realizable else NotStable
397+
if (tp.symbol.isRealizable) Realizable
398+
else if (!tp.symbol.isStable) NotStable
399+
else if (!tp.symbol.isEffectivelyFinal) new NotFinal(tp.symbol)
400+
else new ProblemInUnderlying(tp.info, realizability(tp.info))
398401
case _: SingletonType | NoPrefix =>
399402
Realizable
400403
case tp =>
@@ -643,10 +646,16 @@ object TypeOps {
643646

644647
object Realizable extends Realizability("")
645648

646-
object NotConcrete extends Realizability("is not a concrete type")
649+
object NotConcrete extends Realizability("it is not a concrete type")
647650

648-
object NotStable extends Realizability("is not a stable reference")
651+
object NotStable extends Realizability("it is not a stable reference")
652+
653+
class NotFinal(sym: Symbol)(implicit ctx: Context)
654+
extends Realizability(i"it refers to nonfinal $sym")
649655

650656
class HasProblemBounds(mbr: SingleDenotation)(implicit ctx: Context)
651-
extends Realizability(i"has a member $mbr with possibly empty bounds ${mbr.info.bounds.lo} .. ${mbr.info.bounds.hi}")
657+
extends Realizability(i"it has a member $mbr with possibly conflicting bounds ${mbr.info.bounds.lo} <: ... <: ${mbr.info.bounds.hi}")
658+
659+
class ProblemInUnderlying(tp: Type, problem: Realizability)(implicit ctx: Context)
660+
extends Realizability(i"its underlying type ${tp} ${problem.msg}")
652661
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,14 @@ trait Checking {
318318
}
319319

320320
/** Check that type `tp` is stable. */
321-
def checkStableAndRealizable(tp: Type, pos: Position)(implicit ctx: Context): Unit =
321+
def checkStable(tp: Type, pos: Position)(implicit ctx: Context): Unit =
322322
if (!tp.isStable) ctx.error(d"$tp is not stable", pos)
323-
else checkRealizable(tp, pos)
324323

325324
/** Check that type `tp` is realizable. */
326325
def checkRealizable(tp: Type, pos: Position)(implicit ctx: Context): Unit = {
327326
val rstatus = ctx.realizability(tp)
328327
if (rstatus ne TypeOps.Realizable) {
329-
def msg = d"$tp is not a legal path since it ${rstatus.msg}"
328+
def msg = d"$tp is not a legal path since ${rstatus.msg}"
330329
if (ctx.scala2Mode) ctx.migrationWarning(msg, pos) else ctx.error(msg, pos)
331330
}
332331
}
@@ -339,7 +338,7 @@ trait Checking {
339338
def checkClassTypeWithStablePrefix(tp: Type, pos: Position, traitReq: Boolean)(implicit ctx: Context): Type =
340339
tp.underlyingClassRef(refinementOK = false) match {
341340
case tref: TypeRef =>
342-
if (ctx.phase <= ctx.refchecksPhase) checkStableAndRealizable(tref.prefix, pos)
341+
if (ctx.phase <= ctx.refchecksPhase) checkStable(tref.prefix, pos)
343342
if (traitReq && !(tref.symbol is Trait)) ctx.error(d"$tref is not a trait", pos)
344343
tp
345344
case _ =>
@@ -442,7 +441,7 @@ trait NoChecking extends Checking {
442441
import tpd._
443442
override def checkNonCyclic(sym: Symbol, info: TypeBounds, reportErrors: Boolean)(implicit ctx: Context): Type = info
444443
override def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = tree
445-
override def checkStableAndRealizable(tp: Type, pos: Position)(implicit ctx: Context): Unit = ()
444+
override def checkStable(tp: Type, pos: Position)(implicit ctx: Context): Unit = ()
446445
override def checkRealizable(tp: Type, pos: Position)(implicit ctx: Context): Unit = ()
447446
override def checkClassTypeWithStablePrefix(tp: Type, pos: Position, traitReq: Boolean)(implicit ctx: Context): Type = tp
448447
override def checkImplicitParamsNotSingletons(vparamss: List[List[ValDef]])(implicit ctx: Context): Unit = ()

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
308308
def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = track("typedSelect") {
309309
def asSelect(implicit ctx: Context): Tree = {
310310
val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this))
311-
if (tree.name.isTypeName) checkStableAndRealizable(qual1.tpe, qual1.pos)
311+
if (tree.name.isTypeName) {
312+
checkStable(qual1.tpe, qual1.pos)
313+
checkRealizable(qual1.tpe, qual1.pos)
314+
}
312315
typedSelect(tree, pt, qual1)
313316
}
314317

@@ -342,7 +345,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
342345

343346
def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): Tree = track("typedSelectFromTypeTree") {
344347
val qual1 = typedType(tree.qualifier, selectionProto(tree.name, pt, this))
345-
//checkRealizable(qual1.tpe, qual1.pos)
348+
checkRealizable(qual1.tpe, qual1.pos)
346349
assignType(cpy.SelectFromTypeTree(tree)(qual1, tree.name), qual1)
347350
}
348351

@@ -823,7 +826,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
823826

824827
def typedSingletonTypeTree(tree: untpd.SingletonTypeTree)(implicit ctx: Context): SingletonTypeTree = track("typedSingletonTypeTree") {
825828
val ref1 = typedExpr(tree.ref)
826-
checkStableAndRealizable(ref1.tpe, tree.pos)
829+
checkStable(ref1.tpe, tree.pos)
830+
checkRealizable(ref1.tpe, tree.pos)
827831
assignType(cpy.SingletonTypeTree(tree)(ref1), ref1)
828832
}
829833

@@ -920,8 +924,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
920924
def completeAnnotations(mdef: untpd.MemberDef, sym: Symbol)(implicit ctx: Context): Unit = {
921925
// necessary to force annotation trees to be computed.
922926
sym.annotations.foreach(_.tree)
923-
// necessary in order to mark the typed ahead annotations as definitiely typed:
924-
untpd.modsDeco(mdef).mods.annotations.mapconserve(typedAnnotation)
927+
// necessary in order to mark the typed ahead annotations as definitely typed:
928+
untpd.modsDeco(mdef).mods.annotations.foreach(typedAnnotation)
925929
}
926930

927931
def typedAnnotation(annot: untpd.Tree)(implicit ctx: Context): Tree = track("typedAnnotation") {
@@ -1057,7 +1061,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10571061

10581062
def typedImport(imp: untpd.Import, sym: Symbol)(implicit ctx: Context): Import = track("typedImport") {
10591063
val expr1 = typedExpr(imp.expr, AnySelectionProto)
1060-
checkStableAndRealizable(expr1.tpe, imp.expr.pos)
1064+
checkStable(expr1.tpe, imp.expr.pos)
10611065
assignType(cpy.Import(imp)(expr1, imp.selectors), sym)
10621066
}
10631067

test/dotc/tests.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class tests extends CompilerTest {
4141

4242
val testsDir = "./tests/"
4343
val posDir = testsDir + "pos/"
44-
val posSpecialDir = testsDir + "pos-special/"
44+
val posScala2Dir = testsDir + "pos-scala2/"
4545
val negDir = testsDir + "neg/"
4646
val runDir = testsDir + "run/"
4747
val newDir = testsDir + "new/"
@@ -100,10 +100,7 @@ class tests extends CompilerTest {
100100
@Test def pos_companions = compileFile(posDir, "companions", twice)
101101

102102
@Test def pos_all = compileFiles(posDir) // twice omitted to make tests run faster
103-
104-
@Test def pos_i871 = compileFile(posSpecialDir, "i871", scala2mode)
105-
@Test def pos_variancesConstr = compileFile(posSpecialDir, "variances-constr", scala2mode)
106-
103+
@Test def pos_scala2_all = compileFiles(posScala2Dir, scala2mode)
107104
@Test def new_all = compileFiles(newDir, twice)
108105

109106
@Test def neg_abstractOverride() = compileFile(negDir, "abstract-override", xerrors = 2)
@@ -136,7 +133,7 @@ class tests extends CompilerTest {
136133

137134
@Test def neg_t1843_variances = compileFile(negDir, "t1843-variances", xerrors = 1)
138135
@Test def neg_t2660_ambi = compileFile(negDir, "t2660", xerrors = 2)
139-
@Test def neg_t2994 = compileFile(negDir, "t2994", xerrors = 2)
136+
@Test def neg_t2994 = compileFile(negDir, "t2994", xerrors = 5)
140137
@Test def neg_subtyping = compileFile(negDir, "subtyping", xerrors = 5)
141138
@Test def neg_variances = compileFile(negDir, "variances", xerrors = 2)
142139
@Test def neg_variancesConstr = compileFile(negDir, "variances-constr", xerrors = 2)
@@ -159,7 +156,7 @@ class tests extends CompilerTest {
159156
@Test def neg_i705 = compileFile(negDir, "i705-inner-value-class", xerrors = 7)
160157
@Test def neg_i866 = compileFile(negDir, "i866", xerrors = 2)
161158
@Test def neg_i974 = compileFile(negDir, "i974", xerrors = 2)
162-
@Test def neg_i1050 = compileFile(negDir, "i1050", xerrors = 2)
159+
@Test def neg_i1050 = compileFile(negDir, "i1050", xerrors = 3)
163160
@Test def neg_moduleSubtyping = compileFile(negDir, "moduleSubtyping", xerrors = 4)
164161
@Test def neg_escapingRefs = compileFile(negDir, "escapingRefs", xerrors = 2)
165162
@Test def neg_instantiateAbstract = compileFile(negDir, "instantiateAbstract", xerrors = 8)
@@ -168,7 +165,7 @@ class tests extends CompilerTest {
168165
@Test def neg_selfreq = compileFile(negDir, "selfreq", xerrors = 2)
169166
@Test def neg_singletons = compileFile(negDir, "singletons", xerrors = 8)
170167
@Test def neg_shadowedImplicits = compileFile(negDir, "arrayclone-new", xerrors = 2)
171-
@Test def neg_ski = compileFile(negDir, "ski", xerrors = 2)
168+
@Test def neg_ski = compileFile(negDir, "ski", xerrors = 10)
172169
@Test def neg_traitParamsTyper = compileFile(negDir, "traitParamsTyper", xerrors = 5)
173170
@Test def neg_traitParamsMixin = compileFile(negDir, "traitParamsMixin", xerrors = 2)
174171
@Test def neg_firstError = compileFile(negDir, "firstError", xerrors = 3)

tests/neg/cycles.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class A {
99

1010
class B {
1111
type T <: x.type // error: cycle
12-
val x: T = ???
12+
final val x: T = ???
1313
}
1414

1515
class C {
16-
val x: D#T = ???
16+
final val x: D#T = ??? // error: conflicting bounds
1717
class D {
1818
type T <: x.type // error: cycle
1919
val z: x.type = ???
@@ -25,7 +25,7 @@ class E {
2525
type T <: x.type // error: not stable
2626
val z: x.type = ??? // error: not stable
2727
}
28-
lazy val x: F#T = ???
28+
lazy val x: F#T = ??? // error: conflicting bounds
2929
}
3030

3131
class T1 {
@@ -37,6 +37,6 @@ class T2 {
3737
type U = X | Int
3838
}
3939
object T12 {
40-
??? : (T1 {})#U
41-
??? : (T2 {})#U
40+
??? : (T1 {})#U // error: conflicting bounds
41+
??? : (T2 {})#U // error: conflicting bounds
4242
}

tests/neg/i1050.scala

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ trait A { type L <: Nothing }
22
trait B { type L >: Any}
33
object Test {
44
lazy val x: A & B = ???
5-
val y: x.L = 1
5+
val y: x.L = 1 // error: underlying conflicting bounds
66
val z: String = y
77
}
88
object Test50 {
@@ -14,11 +14,69 @@ object Test50 {
1414
}
1515
lazy val o: A & B = ???
1616

17-
def xToString(x: o.X): String = x
17+
def xToString(x: o.X): String = x // error: underlying conflicting bounds
1818

1919
def intToString(i: Int): String = xToString(i)
2020

2121
def main(args: Array[String]) = {
2222
val s: String = intToString(1)
2323
}
2424
}
25+
object Test2 {
26+
27+
trait C { type A }
28+
29+
type T = C { type A = Any }
30+
type U = C { type A = Nothing }
31+
type X = T & U
32+
33+
def main(args: Array[String]) = {
34+
val y: X#A = 1 // error: conflicting bounds
35+
val z: String = y
36+
}
37+
}
38+
object Tiark1 {
39+
trait A { type L <: Nothing }
40+
trait B { type L >: Any}
41+
trait U {
42+
val p: B
43+
def brand(x: Any): p.L = x // error: not final
44+
}
45+
trait V extends U {
46+
lazy val p: A & B = ???
47+
}
48+
val v = new V {}
49+
v.brand("boom!")
50+
}
51+
object Tiark2 {
52+
trait A { type L <: Nothing }
53+
trait B { type L >: Any}
54+
trait U {
55+
type X <: B
56+
val p: X
57+
def brand(x: Any): p.L = x // error: not final
58+
}
59+
trait V extends U {
60+
type X = B & A
61+
lazy val p: X = ???
62+
}
63+
val v = new V {}
64+
v.brand("boom!"): Nothing
65+
}
66+
/*
67+
object Import {
68+
trait A { type L <: Nothing }
69+
trait B { type L >: Any}
70+
trait U {
71+
val p: B
72+
def brand(x: Any): p.L = x // error: not final
73+
locally { import p._
74+
}
75+
}
76+
trait V extends U {
77+
lazy val p: A & B = ???
78+
}
79+
val v = new V {}
80+
v.brand("boom!")
81+
}
82+
*/

tests/neg/ski.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ trait S2[x <: Term, y <: Term] extends Term {
1717
type eval = S2[x, y]
1818
}
1919
trait S3[x <: Term, y <: Term, z <: Term] extends Term {
20-
type ap[v <: Term] = eval#ap[v]
21-
type eval = x#ap[z]#ap[y#ap[z]]#eval
20+
type ap[v <: Term] = eval#ap[v] // error
21+
type eval = x#ap[z]#ap[y#ap[z]]#eval // error // error
2222
}
2323

2424
// The K combinator
@@ -31,8 +31,8 @@ trait K1[x <: Term] extends Term {
3131
type eval = K1[x]
3232
}
3333
trait K2[x <: Term, y <: Term] extends Term {
34-
type ap[z <: Term] = eval#ap[z]
35-
type eval = x#eval
34+
type ap[z <: Term] = eval#ap[z] // error
35+
type eval = x#eval // error
3636
}
3737

3838
// The I combinator
@@ -41,8 +41,8 @@ trait I extends Term {
4141
type eval = I
4242
}
4343
trait I1[x <: Term] extends Term {
44-
type ap[y <: Term] = eval#ap[y]
45-
type eval = x#eval
44+
type ap[y <: Term] = eval#ap[y] // error
45+
type eval = x#eval // error
4646
}
4747

4848
// Constants
@@ -64,9 +64,9 @@ case class Equals[A >: B <:B , B]()
6464

6565
object Test {
6666
type T1 = Equals[Int, Int] // compiles fine
67-
type T2 = Equals[String, Int] // error
67+
type T2 = Equals[String, Int] // was error, now masked
6868
type T3 = Equals[I#ap[c]#eval, c]
69-
type T3a = Equals[I#ap[c]#eval, d]// error
69+
type T3a = Equals[I#ap[c]#eval, d] // was error, now masked
7070

7171
// Ic -> c
7272
type T4 = Equals[I#ap[c]#eval, c]
@@ -106,11 +106,11 @@ object Test {
106106
type eval = A0
107107
}
108108
trait A1 extends Term {
109-
type ap[x <: Term] = x#ap[A0]#eval
109+
type ap[x <: Term] = x#ap[A0]#eval // error
110110
type eval = A1
111111
}
112112
trait A2 extends Term {
113-
type ap[x <: Term] = x#ap[A1]#eval
113+
type ap[x <: Term] = x#ap[A1]#eval // error
114114
type eval = A2
115115
}
116116

@@ -126,7 +126,7 @@ object Test {
126126
type T15 = Equals[NN3#eval, c]
127127

128128
trait An extends Term {
129-
type ap[x <: Term] = x#ap[An]#eval
129+
type ap[x <: Term] = x#ap[An]#eval // error
130130
type eval = An
131131
}
132132

tests/neg/t2994.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Naturals {
77
type a[s[_ <: NAT] <: NAT, z <: NAT] = z
88
}
99
final class SUCC[n <: NAT] extends NAT {
10-
type a[s[_ <: NAT] <: NAT, z <: NAT] = s[n#a[s, z]]
10+
type a[s[_ <: NAT] <: NAT, z <: NAT] = s[n#a[s, z]] // error: not a legal path
1111
}
1212
type _0 = ZERO
1313
type _1 = SUCC[_0]
@@ -21,8 +21,8 @@ object Naturals {
2121
// crashes scala-2.8.0 beta1
2222
trait MUL[n <: NAT, m <: NAT] extends NAT {
2323
trait curry[n[_[_], _], s[_]] { type f[z <: NAT] = n[s, z] } // can't do double param lists:
24-
// error: `]' expected but `[` found.
25-
type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z]
24+
// error: `]' expected but `[` found. // error: wrong number of type arguments
25+
type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z] // error: not a legal path // error: not a legal path
2626
}
2727

2828
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/pos-special/i871.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)