Browse files

Created utility function for dropping by-name-ness.

And applied it in three locations.
  • Loading branch information...
1 parent b291e28 commit 4ca6eb8847f7fbc2374f9ed465cf3076056b0646 @paulp paulp committed Apr 25, 2013
View
12 src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -38,10 +38,7 @@ trait Infer extends Checkable {
* @param removeRepeated allows keeping repeated parameter (if there's one argument). Used in NamesDefaults.
*/
def formalTypes(formals: List[Type], nargs: Int, removeByName: Boolean = true, removeRepeated: Boolean = true): List[Type] = {
- val formals1 = if (removeByName) formals mapConserve {
- case TypeRef(_, ByNameParamClass, List(arg)) => arg
- case formal => formal
- } else formals
+ val formals1 = if (removeByName) formals mapConserve dropByName else formals
if (isVarArgTypes(formals1) && (removeRepeated || formals.length != nargs)) {
val ft = formals1.last.dealiasWiden.typeArgs.head
formals1.init ::: (for (i <- List.range(formals1.length - 1, nargs)) yield ft)
@@ -412,10 +409,9 @@ trait Infer extends Checkable {
* since that induces a tie between m(=>A) and m(=>A,B*) [SI-3761]
*/
private def isCompatible(tp: Type, pt: Type): Boolean = {
- def isCompatibleByName(tp: Type, pt: Type): Boolean = pt match {
- case TypeRef(_, ByNameParamClass, List(res)) if !isByNameParamType(tp) => isCompatible(tp, res)
- case _ => false
- }
+ def isCompatibleByName(tp: Type, pt: Type): Boolean = (
+ isByNameParamType(pt) && !isByNameParamType(tp) && isCompatible(tp, dropByName(pt))
+ )
val tp1 = normalize(tp)
(tp1 weak_<:< pt) || isCoercible(tp1, pt) || isCompatibleByName(tp, pt)
}
View
5 src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -466,10 +466,7 @@ trait NamesDefaults { self: Analyzer =>
val udp = context.undetparams
context.savingUndeterminedTypeParams(reportAmbiguous = false) {
val subst = new SubstTypeMap(udp, udp map (_ => WildcardType)) {
- override def apply(tp: Type): Type = super.apply(tp match {
- case TypeRef(_, ByNameParamClass, x :: Nil) => x
- case _ => tp
- })
+ override def apply(tp: Type): Type = super.apply(dropByName(tp))
}
// This throws an exception which is caught in `tryTypedApply` (as it
// uses `silent`) - unfortunately, tryTypedApply recovers from the
View
4 src/reflect/scala/reflect/internal/Definitions.scala
@@ -404,6 +404,10 @@ trait Definitions extends api.StandardDefinitions {
lazy val JavaRepeatedParamClass = specialPolyClass(tpnme.JAVA_REPEATED_PARAM_CLASS_NAME, COVARIANT)(tparam => arrayType(tparam.tpe))
lazy val RepeatedParamClass = specialPolyClass(tpnme.REPEATED_PARAM_CLASS_NAME, COVARIANT)(tparam => seqType(tparam.tpe))
+ def dropByName(tp: Type): Type = tp match {
+ case TypeRef(_, ByNameParamClass, arg :: Nil) => arg
+ case _ => tp
+ }
def isByNameParamType(tp: Type) = tp.typeSymbol == ByNameParamClass
def isScalaRepeatedParamType(tp: Type) = tp.typeSymbol == RepeatedParamClass
def isJavaRepeatedParamType(tp: Type) = tp.typeSymbol == JavaRepeatedParamClass

0 comments on commit 4ca6eb8

Please sign in to comment.