summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-01-03 20:16:21 +0000
committerPaul Phillips <paulp@improving.org>2011-01-03 20:16:21 +0000
commitcb10f8a9ff1e2eff1fdca76ffac64962a1bb5ac6 (patch)
tree7dab999829005043bf508f49a8db9460e8d32a3a /src
parent4e0d481418774c6013d03bfb16a553e47a075779 (diff)
downloadscala-cb10f8a9ff1e2eff1fdca76ffac64962a1bb5ac6.tar.gz
scala-cb10f8a9ff1e2eff1fdca76ffac64962a1bb5ac6.tar.bz2
scala-cb10f8a9ff1e2eff1fdca76ffac64962a1bb5ac6.zip
Since r22374 isCompatible and isCompatibleArg h...
Since r22374 isCompatible and isCompatibleArg have been bit-for-bit identical methods. Deleted isCompatibleArg. Also gave some structure to the act of disabling implicit search. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala7
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala41
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala5
3 files changed, 21 insertions, 32 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index eb96a6fba6..7f0be68fca 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -138,6 +138,13 @@ trait Contexts { self: Analyzer =>
tparams
}
+ def withImplicitsDisabled[T](op: => T): T = {
+ val saved = implicitsEnabled
+ implicitsEnabled = false
+ try op
+ finally implicitsEnabled = saved
+ }
+
/**
* @param unit ...
* @param tree ...
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 107d3a07a7..19706e119c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -358,11 +358,6 @@ trait Infer {
true
}
- def isCompatible(tp: Type, pt: Type): Boolean = {
- val tp1 = normalize(tp)
- (tp1 weak_<:< pt) || isCoercible(tp1, pt)
- }
-
final def normSubType(tp: Type, pt: Type): Boolean = tp match {
case mt @ MethodType(params, restpe) =>
if (mt.isImplicit) normSubType(restpe, pt)
@@ -398,10 +393,12 @@ trait Infer {
tp <:< pt
}
- def isCompatibleArg(tp: Type, pt: Type): Boolean = {
+ def isCompatible(tp: Type, pt: Type): Boolean = {
val tp1 = normalize(tp)
(tp1 weak_<:< pt) || isCoercible(tp1, pt)
}
+ def isCompatibleArgs(tps: List[Type], pts: List[Type]) =
+ (tps corresponds pts)(isCompatible)
def isWeaklyCompatible(tp: Type, pt: Type): Boolean =
pt.typeSymbol == UnitClass || // can perform unit coercion
@@ -412,21 +409,11 @@ trait Infer {
/** Like weakly compatible but don't apply any implicit conversions yet.
* Used when comparing the result type of a method with its prototype.
*/
- def isConservativelyCompatible(tp: Type, pt: Type): Boolean = {
- val savedImplicitsEnabled = context.implicitsEnabled
- context.implicitsEnabled = false
- try {
- isWeaklyCompatible(tp, pt)
- } finally {
- context.implicitsEnabled = savedImplicitsEnabled
- }
- }
+ def isConservativelyCompatible(tp: Type, pt: Type): Boolean =
+ context.withImplicitsDisabled(isWeaklyCompatible(tp, pt))
def isCoercible(tp: Type, pt: Type): Boolean = false
- def isCompatibleArgs(tps: List[Type], pts: List[Type]) =
- (tps corresponds pts)(isCompatibleArg)
-
/* -- Type instantiation------------------------------------------------ */
/** Replace any (possibly bounded) wildcard types in type `tp`
@@ -653,7 +640,7 @@ trait Infer {
// Then define remaining type variables from argument types.
(argtpes, formals).zipped map { (argtpe, formal) =>
//@M isCompatible has side-effect: isSubtype0 will register subtype checks in the tvar's bounds
- if (!isCompatibleArg(argtpe.deconst.instantiateTypeParams(tparams, tvars),
+ if (!isCompatible(argtpe.deconst.instantiateTypeParams(tparams, tvars),
formal.instantiateTypeParams(tparams, tvars))) {
throw new DeferredNoInstance(() =>
"argument expression's type is not compatible with formal parameter type" +
@@ -1640,20 +1627,18 @@ trait Infer {
if (context.implicitsEnabled) {
val reportGeneralErrors = context.reportGeneralErrors
context.reportGeneralErrors = false
- context.implicitsEnabled = false
try {
- infer
- } catch {
- case ex: CyclicReference =>
- throw ex
- case ex: TypeError =>
+ context.withImplicitsDisabled(infer)
+ }
+ catch {
+ case ex: CyclicReference => throw ex
+ case ex: TypeError =>
context.reportGeneralErrors = reportGeneralErrors
- context.implicitsEnabled = true
infer
}
context.reportGeneralErrors = reportGeneralErrors
- context.implicitsEnabled = true
- } else infer
+ }
+ else infer
}
/** Assign <code>tree</code> the type of unique polymorphic alternative
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 5ce685ed73..ca7e6ed379 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4194,10 +4194,7 @@ trait Typers extends Modes {
// We disable implicits because otherwise some constructs will
// type check which should not. The pattern matcher does not
// perform implicit conversions in an attempt to consummate a match.
- val savedImplicitsEnabled = context.implicitsEnabled
- context.implicitsEnabled = false
- try typed(tree, PATTERNmode, pt)
- finally context.implicitsEnabled = savedImplicitsEnabled
+ context.withImplicitsDisabled(typed(tree, PATTERNmode, pt))
}
/** Types a (fully parameterized) type tree */