summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-02-02 15:11:43 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-02-03 14:31:34 +1000
commitcc2e613189ce78d160ab88281736df948361c6ad (patch)
treeb8db2e4cce5ed863048cc4f2372446565db41c06 /src
parent178e8df9b6a91375a6162721a0cbc2d90bcc7451 (diff)
downloadscala-cc2e613189ce78d160ab88281736df948361c6ad.tar.gz
scala-cc2e613189ce78d160ab88281736df948361c6ad.tar.bz2
scala-cc2e613189ce78d160ab88281736df948361c6ad.zip
SI-9131 Fix use of apply syntactic sugar with by-name param
After typechecking a tree, the typer adapts it to the current mode and expected type. If we are in FUNmode (typechecking the qualifier of a value- or type-application), and the tree does not already have a MethodType or PolyType, it is reinterepreted as `qual.apply`. In doing so, `insertApply` stabilizes the type of `qual`, e.g. replacing `Ident(foo).setType(typeOf[Int])` with `Ident(foo).setType(typeOf[foo.type])`. However, this does not check for by-name parameters, which cannot form the basis for a singleton type, as we can see by trying that directly: ``` scala> def foo(a: => String) { type T = a.type } <console>:7: error: stable identifier required, but a.type found. def foo(a: => String) { type T = a.type } ^ ``` When I last touched this code in SI-6206 / 267650cf9, I noted: // TODO reconcile the overlap between Typers#stablize and TreeGen.stabilize I didn't get around to that, but Adriaan gave that code a thorough cleanup in fada1ef6b. It appears that on the back of his work, we can now remove the local stabilization logic in `insertApply` in favour of `TreeGen.stabilize`. We then avoid the ill-formed singleton type, and the spurious "apply is not a member" type error. I did have to modify `isStableIdent` to check the symbol's info in addition to the tree's type for by-name-ness.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala19
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala1
2 files changed, 2 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 2dd79075ee..e883bacc88 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -918,24 +918,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
def insertApply(): Tree = {
assert(!context.inTypeConstructorAllowed, mode) //@M
val adapted = adaptToName(tree, nme.apply)
- def stabilize0(pre: Type): Tree = stabilize(adapted, pre, MonoQualifierModes, WildcardType)
-
- // TODO reconcile the overlap between Typers#stablize and TreeGen.stabilize
- val qual = adapted match {
- case This(_) =>
- gen.stabilize(adapted)
- case Ident(_) =>
- val owner = adapted.symbol.owner
- val pre =
- if (owner.isPackageClass) owner.thisType
- else if (owner.isClass) context.enclosingSubClassContext(owner).prefix
- else NoPrefix
- stabilize0(pre)
- case Select(qualqual, _) =>
- stabilize0(qualqual.tpe)
- case other =>
- other
- }
+ val qual = gen.stabilize(adapted)
typedPos(tree.pos, mode, pt) {
Select(qual setPos tree.pos.makeTransparent, nme.apply)
}
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index 4657fa0000..7ad5fdf096 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -128,6 +128,7 @@ abstract class TreeInfo {
symOk(tree.symbol)
&& tree.symbol.isStable
&& !definitions.isByNameParamType(tree.tpe)
+ && !definitions.isByName(tree.symbol)
&& (allowVolatile || !tree.symbol.hasVolatileType) // TODO SPEC: not required by spec
)