Skip to content

Commit cf29806

Browse files
committed
Handle imports in path checks.
If `T` is a member of `p` then { import p._; ... T ... } should be checked in the same way as { ... p.T ... }
1 parent efe1bf2 commit cf29806

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
274274

275275
val tree1 = ownType match {
276276
case ownType: NamedType if !prefixIsElidable(ownType) =>
277+
checkRealizable(ownType.prefix, tree.pos)
277278
ref(ownType).withPos(tree.pos)
278279
case _ =>
279280
tree.withType(ownType)
@@ -991,6 +992,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
991992
val impl1 = cpy.Template(impl)(constr1, parents1, self1, body1)
992993
.withType(dummy.nonMemberTermRef)
993994
checkVariance(impl1)
995+
if (!cls.is(AbstractOrTrait)) checkRealizableBounds(cls.typeRef, cdef.pos)
994996
assignType(cpy.TypeDef(cdef)(name, impl1, Nil), cls)
995997

996998
// todo later: check that

test/dotc/tests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class tests extends CompilerTest {
156156
@Test def neg_i705 = compileFile(negDir, "i705-inner-value-class", xerrors = 7)
157157
@Test def neg_i866 = compileFile(negDir, "i866", xerrors = 2)
158158
@Test def neg_i974 = compileFile(negDir, "i974", xerrors = 2)
159-
@Test def neg_i1050 = compileFile(negDir, "i1050", xerrors = 6)
159+
@Test def neg_i1050 = compileFile(negDir, "i1050", xerrors = 8)
160160
@Test def neg_i1050a = compileFile(negDir, "i1050a", xerrors = 2)
161161
@Test def neg_moduleSubtyping = compileFile(negDir, "moduleSubtyping", xerrors = 4)
162162
@Test def neg_escapingRefs = compileFile(negDir, "escapingRefs", xerrors = 2)

tests/neg/i1050.scala

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object Tiark1 {
4040
trait B { type L >: Any}
4141
trait U {
4242
lazy val p: B
43-
def brand(x: Any): p.L = x // error: not final
43+
def brand(x: Any): p.L = x // error: nonfinal lazy
4444
}
4545
trait V extends U {
4646
lazy val p: A & B = ???
@@ -54,7 +54,7 @@ object Tiark2 {
5454
trait U {
5555
type X <: B
5656
lazy val p: X
57-
def brand(x: Any): p.L = x // error: not final
57+
def brand(x: Any): p.L = x // error: nonfinal lazy
5858
}
5959
trait V extends U {
6060
type X = B & A
@@ -70,7 +70,7 @@ object Tiark3 {
7070
type X <: B
7171
def p2: X
7272
final lazy val p: X = p2
73-
def brand(x: Any): p.L = x
73+
def brand(x: Any): p.L = x // error: underlying not concrete
7474
}
7575
trait V extends U {
7676
type X = B with A
@@ -79,20 +79,18 @@ object Tiark3 {
7979
val v = new V {}
8080
v.brand("boom!"): Nothing
8181
}
82-
/*
8382
object Import {
8483
trait A { type L <: Nothing }
8584
trait B { type L >: Any}
8685
trait U {
87-
val p: B
88-
def brand(x: Any): p.L = x // error: not final
89-
locally { import p._
86+
lazy val p: B
87+
locally { val x: p.L = ??? } // error: nonfinal lazy
88+
locally {
89+
import p._
90+
val x: L = ??? // error: nonfinal lazy
9091
}
9192
}
9293
trait V extends U {
9394
lazy val p: A & B = ???
94-
}
95-
val v = new V {}
96-
v.brand("boom!")
9795
}
98-
*/
96+

0 commit comments

Comments
 (0)