diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-25 17:16:11 +0200 |
---|---|---|
committer | phaller <hallerp@gmail.com> | 2012-12-10 16:01:21 +0100 |
commit | 98b16a6bd2d95c1378ff7b50b7858e917a67d559 (patch) | |
tree | 29eac97ef988439e460a1e28793b591887c6d277 | |
parent | 3d2bcf2466d4058883054c99632cb007300ed368 (diff) | |
download | scala-98b16a6bd2d95c1378ff7b50b7858e917a67d559.tar.gz scala-98b16a6bd2d95c1378ff7b50b7858e917a67d559.tar.bz2 scala-98b16a6bd2d95c1378ff7b50b7858e917a67d559.zip |
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
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeGen.scala | 2 | ||||
-rw-r--r-- | test/files/pos/t5958.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t5958.scala | 15 |
3 files changed, 18 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index 268e104309..63c5b66243 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -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 diff --git a/test/files/pos/t5958.flags b/test/files/pos/t5958.flags new file mode 100644 index 0000000000..a7ed61704f --- /dev/null +++ b/test/files/pos/t5958.flags @@ -0,0 +1 @@ +-Ydependent-method-types diff --git a/test/files/pos/t5958.scala b/test/files/pos/t5958.scala new file mode 100644 index 0000000000..b7eb8cf8df --- /dev/null +++ b/test/files/pos/t5958.scala @@ -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 + } +} |