Skip to content

Commit a7b4c14

Browse files
committed
Fix #1009: Do not forget to skolemize some illegal prefixes
1 parent c66613d commit a7b4c14

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
4545
* The scheme is efficient in particular because we expect that unsafe situations are rare;
4646
* most compiles would contain none, so no scanning would be necessary.
4747
*/
48-
final def asSeenFrom(tp: Type, pre: Type, cls: Symbol): Type =
49-
asSeenFrom(tp, pre, cls, null)
48+
final def asSeenFrom(tp: Type, pre: Type, cls: Symbol): Type = {
49+
val m = if (isLegalPrefix(pre)) null else new AsSeenFromMap(pre, cls)
50+
asSeenFrom(tp, pre, cls, m)
51+
}
5052

5153
/** Helper method, taking a map argument which is instantiated only for more
5254
* complicated cases of asSeenFrom.

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class tests extends CompilerTest {
172172
@Test def neg_validate = compileFile(negDir, "validate", xerrors = 18)
173173
@Test def neg_validateParsing = compileFile(negDir, "validate-parsing", xerrors = 7)
174174
@Test def neg_validateRefchecks = compileFile(negDir, "validate-refchecks", xerrors = 2)
175+
@Test def neg_skolemize = compileFile(negDir, "skolemize", xerrors = 2)
175176

176177
@Test def run_all = runFiles(runDir)
177178

tests/neg/skolemize.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Contra[-T]
2+
3+
class Foo {
4+
val foo: Contra[this.type] = new Contra[this.type]
5+
}
6+
object Test {
7+
def test: Unit = {
8+
val e1 = new Foo
9+
val f1: Contra[Foo] = e1.foo // error
10+
var e2 = new Foo
11+
val f2: Contra[Foo] = e2.foo // error
12+
}
13+
}

0 commit comments

Comments
 (0)