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