diff options
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/scala/reflect/internal/Definitions.scala | 18 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Types.scala | 5 |
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 |