summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2016-03-16 16:37:59 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2016-03-26 22:49:15 -0700
commit1acfc70b038b09018d3ba1cc4b8c968e2a93d33c (patch)
tree02dc96cbe07eb98c94e5ca74631c3f0124be9711 /src/reflect
parentad90614c391328bdc9d13795d26f339f67e7f4d5 (diff)
downloadscala-1acfc70b038b09018d3ba1cc4b8c968e2a93d33c.tar.gz
scala-1acfc70b038b09018d3ba1cc4b8c968e2a93d33c.tar.bz2
scala-1acfc70b038b09018d3ba1cc4b8c968e2a93d33c.zip
Set the scene for Sammy.
Go beyond refactoring and introduce some hooks and patch some holes that will become acute when we set Sammy loose. Expanding sam requires class as first parent: `addObjectParent`. (Tested in pos/sam_ctor_arg.scala, coming next.)
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala18
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala5
2 files changed, 23 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 9a212fcbcb..2fa39bc453 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -686,11 +686,29 @@ trait Definitions extends api.StandardDefinitions {
}
}
+ // the result type of a function or corresponding SAM type
+ def functionResultType(tp: Type): Type = {
+ val dealiased = tp.dealiasWiden
+ if (isFunctionTypeDirect(dealiased)) dealiased.typeArgs.last
+ else samOf(tp) match {
+ case samSym if samSym.exists => tp.memberInfo(samSym).resultType.deconst
+ case _ => NoType
+ }
+ }
+
// the SAM's parameters and the Function's formals must have the same length
// (varargs etc don't come into play, as we're comparing signatures, not checking an application)
def samMatchesFunctionBasedOnArity(sam: Symbol, formals: List[Any]): Boolean =
sam.exists && sameLength(sam.info.params, formals)
+ def samMatchingFunction(tree: Tree, pt: Type): Symbol = {
+ if (tree.isInstanceOf[Function] && !isFunctionType(pt)) {
+ val sam = samOf(pt)
+ if (samMatchesFunctionBasedOnArity(sam, tree.asInstanceOf[Function].vparams)) sam
+ else NoSymbol
+ } else NoSymbol
+ }
+
def isTupleType(tp: Type) = isTupleTypeDirect(tp.dealiasWiden)
def tupleComponents(tp: Type) = tp.dealiasWiden.typeArgs
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index f385ca08c9..00df55f044 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -4553,6 +4553,11 @@ trait Types
else (ps :+ SerializableTpe).toList
)
+ def addObjectParent(tps: List[Type]) = tps match {
+ case hd :: _ if hd.typeSymbol.isTrait => ObjectTpe :: tps
+ case _ => tps
+ }
+
/** Adds the @uncheckedBound annotation if the given `tp` has type arguments */
final def uncheckedBounds(tp: Type): Type = {
if (tp.typeArgs.isEmpty || UncheckedBoundsClass == NoSymbol) tp // second condition for backwards compatibility with older scala-reflect.jar