summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/parser
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2016-03-30 17:17:34 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2016-03-30 20:07:34 -0700
commit8e32d00e1679114ee1b3f9a90f235d2ab9feba2e (patch)
treeb7bb9f449797b561baf0a10a7eab004f01a8cf24 /src/compiler/scala/tools/nsc/ast/parser
parent7025be9a468419ca6076d78f8da32c6a667fc829 (diff)
downloadscala-8e32d00e1679114ee1b3f9a90f235d2ab9feba2e.tar.gz
scala-8e32d00e1679114ee1b3f9a90f235d2ab9feba2e.tar.bz2
scala-8e32d00e1679114ee1b3f9a90f235d2ab9feba2e.zip
Keep Function when CBN arg thunk targets a SAM
The body of `def delay[T](v: => T) = (v _): F0[T]` becomes `() => v` during `typedEta`, and then uncurry considers whether to strip the function wrapper since `v` is known to be a `Function0` thunk. Stripping is sound when the expected type is `Function0` for this expression, but that's no longer a given, since we could be expecting any nullary SAM. Also sweep up a bit around `typedEta`. Encapsulate the, erm, creative encoding of `m _` as `Typed(m, Function(Nil, EmptyTree))`.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala4
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala3
2 files changed, 4 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index d4715471f6..9c0174d89b 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -1713,9 +1713,7 @@ self =>
}
simpleExprRest(app, canApply = true)
case USCORE =>
- atPos(t.pos.start, in.skipToken()) {
- Typed(stripParens(t), Function(Nil, EmptyTree))
- }
+ atPos(t.pos.start, in.skipToken()) { makeMethodValue(stripParens(t)) }
case _ =>
t
}
diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
index 473a40f42a..1e9a1762eb 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
@@ -35,6 +35,9 @@ abstract class TreeBuilder {
def repeatedApplication(tpe: Tree): Tree =
AppliedTypeTree(rootScalaDot(tpnme.REPEATED_PARAM_CLASS_NAME), List(tpe))
+ // represents `expr _`, as specified in Method Values of spec/06-expressions.md
+ def makeMethodValue(expr: Tree): Tree = Typed(expr, Function(Nil, EmptyTree))
+
def makeImportSelector(name: Name, nameOffset: Int): ImportSelector =
ImportSelector(name, nameOffset, name, nameOffset)