Skip to content

Commit ff87fbb

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

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-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.

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)