Skip to content

Commit 1a6a714

Browse files
committed
Fix incorrect "self reference in refinement is deprecated" warning
The check used to disallow any reference of the form `X.this.type` even though `X` is never the refinement class. This change mirrors the check done with `ThisType` a couple of line below.
1 parent 68c4c13 commit 1a6a714

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ object Checking {
412412
case tree: RefTree =>
413413
checkRef(tree, tree.symbol)
414414
foldOver(x, tree)
415-
case tree: This =>
415+
case tree: This if tree.tpe.classSymbol == refineCls =>
416416
selfRef(tree)
417417
case tree: TypeTree =>
418418
val checkType = new TypeAccumulator[Unit] {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Outer:
2+
type X = { type O = Outer.this.type } // ok
3+
type Y = { type O = this.type } // error

tests/pos/polymorphic-functions-this.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ trait Foo:
44
val f: [T <: this.X] => (T, this.X) => (T, this.X) =
55
[T <: this.X] => (x: T, y: this.X) => (x, y)
66
f(x, x)
7+
8+
val g: [T <: this.type] => (T, this.type) => (T, this.type) =
9+
[T <: this.type] => (x: T, y: this.type) => (x, y)
10+
g(this, this)

0 commit comments

Comments
 (0)