Skip to content

Commit 98b16a6

Browse files
Adriaan Moorsphaller
authored andcommitted
SI-5958 This deserves a stable type - backport to 2.9.x
`this` (or the self variable) passed as an actual argument to a method should receive a singleton type when computing the method's resultType this is necessary if the method's type depends on that argument adapts the test so that it runs on 2.9.x
1 parent 3d2bcf2 commit 98b16a6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/compiler/scala/tools/nsc/ast/TreeGen.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ abstract class TreeGen {
124124

125125
/** Computes stable type for a tree if possible */
126126
def stableTypeFor(tree: Tree): Option[Type] = tree match {
127+
case This(_) if tree.symbol != null && !tree.symbol.isError =>
128+
Some(ThisType(tree.symbol))
127129
case Ident(_) if tree.symbol.isStable =>
128130
Some(singleType(tree.symbol.owner.thisType, tree.symbol))
129131
case Select(qual, _) if ((tree.symbol ne null) && (qual.tpe ne null)) && // turned assert into guard for #4064

test/files/pos/t5958.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Ydependent-method-types

test/files/pos/t5958.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Test {
2+
def newComponent(u: Universe): u.Component = throw new Exception("not implemented")
3+
4+
class Universe { self =>
5+
class Component
6+
7+
newComponent(this): this.Component // error, but should be fine since this is a stable reference
8+
newComponent(self): self.Component // error, but should be fine since this is a stable reference
9+
newComponent(self): this.Component // error, but should be fine since this is a stable reference
10+
newComponent(this): self.Component // error, but should be fine since this is a stable reference
11+
12+
val u = this
13+
newComponent(u): u.Component // ok
14+
}
15+
}

0 commit comments

Comments
 (0)