Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 98b16a6bd2d95c1378ff7b50b7858e917a67d559 1 parent 3d2bcf2
Adriaan Moors adriaanm authored phaller committed
2  src/compiler/scala/tools/nsc/ast/TreeGen.scala
View
@@ -124,6 +124,8 @@ abstract class TreeGen {
/** Computes stable type for a tree if possible */
def stableTypeFor(tree: Tree): Option[Type] = tree match {
+ case This(_) if tree.symbol != null && !tree.symbol.isError =>
+ Some(ThisType(tree.symbol))
case Ident(_) if tree.symbol.isStable =>
Some(singleType(tree.symbol.owner.thisType, tree.symbol))
case Select(qual, _) if ((tree.symbol ne null) && (qual.tpe ne null)) && // turned assert into guard for #4064
1  test/files/pos/t5958.flags
View
@@ -0,0 +1 @@
+-Ydependent-method-types
15 test/files/pos/t5958.scala
View
@@ -0,0 +1,15 @@
+class Test {
+ def newComponent(u: Universe): u.Component = throw new Exception("not implemented")
+
+ class Universe { self =>
+ class Component
+
+ newComponent(this): this.Component // error, but should be fine since this is a stable reference
+ newComponent(self): self.Component // error, but should be fine since this is a stable reference
+ newComponent(self): this.Component // error, but should be fine since this is a stable reference
+ newComponent(this): self.Component // error, but should be fine since this is a stable reference
+
+ val u = this
+ newComponent(u): u.Component // ok
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.