Skip to content

Commit 68c4c13

Browse files
committed
Fix meaning of this in a polymorphic function type
1 parent a7b3854 commit 68c4c13

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ trait TypeAssigner {
2222
*/
2323
def qualifyingClass(tree: untpd.Tree, qual: Name, packageOK: Boolean)(using Context): Symbol = {
2424
def qualifies(sym: Symbol) =
25-
sym.isClass && (
25+
sym.isClass &&
26+
// `this` in a polymorphic function type never refers to the desugared refinement.
27+
// In other refinements, `this` does refer to the refinement but is deprecated
28+
// (see `Checking#checkRefinementNonCyclic`).
29+
!(sym.isRefinementClass && sym.derivesFrom(defn.PolyFunctionClass)) && (
2630
qual.isEmpty ||
2731
sym.name == qual ||
2832
sym.is(Module) && sym.name.stripModuleClassSuffix == qual)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait Foo:
2+
type X
3+
def x: X
4+
val f: [T <: this.X] => (T, this.X) => (T, this.X) =
5+
[T <: this.X] => (x: T, y: this.X) => (x, y)
6+
f(x, x)

0 commit comments

Comments
 (0)