diff options
author | Paul Phillips <paulp@improving.org> | 2013-03-22 13:40:02 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-03-22 13:40:02 -0700 |
commit | a16441c1d2b35980b3cca22325b1b826c5c684a4 (patch) | |
tree | 61a0d2631c570ff84b25ed6ef2586ca147b84656 | |
parent | 426cec50f343f6c936349e7e0cab774423218d66 (diff) | |
parent | 4bb8988e0263206fc914537c7762b0ee3b9057aa (diff) | |
download | scala-a16441c1d2b35980b3cca22325b1b826c5c684a4.tar.gz scala-a16441c1d2b35980b3cca22325b1b826c5c684a4.tar.bz2 scala-a16441c1d2b35980b3cca22325b1b826c5c684a4.zip |
Merge pull request #2259 from Blaisorblade/issue/6123-try-3
SI-6123: -explaintypes should not explain errors which won't be reported, new attempt
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 6 | ||||
-rw-r--r-- | test/files/neg/abstract-explaintypes.check | 11 | ||||
-rw-r--r-- | test/files/neg/abstract-explaintypes.flags | 1 | ||||
-rw-r--r-- | test/files/neg/abstract-explaintypes.scala | 11 | ||||
-rw-r--r-- | test/files/pos/t6123-explaintypes-implicits.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t6123-explaintypes-implicits.scala | 13 | ||||
-rw-r--r-- | test/files/pos/t6123-explaintypes-macros.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t6123-explaintypes-macros.scala | 7 |
9 files changed, 53 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 86ee7939c8..17e679b5dd 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -172,8 +172,7 @@ trait ContextErrors { assert(!foundType.isErroneous && !req.isErroneous, (foundType, req)) issueNormalTypeError(tree, withAddendum(tree.pos)(typeErrorMsg(foundType, req, infer.isPossiblyMissingArgs(foundType, req))) ) - if (settings.explaintypes.value) - explainTypes(foundType, req) + infer.explainTypes(foundType, req) } def WithFilterError(tree: Tree, ex: AbsTypeError) = { @@ -1273,11 +1272,12 @@ trait ContextErrors { // not exactly an error generator, but very related // and I dearly wanted to push it away from Macros.scala private def checkSubType(slot: String, rtpe: Type, atpe: Type) = { - val ok = if (macroDebugVerbose || settings.explaintypes.value) { - if (rtpe eq atpe) println(rtpe + " <: " + atpe + "?" + EOL + "true") + val ok = if (macroDebugVerbose) { withTypesExplained(rtpe <:< atpe) } else rtpe <:< atpe if (!ok) { + if (!macroDebugVerbose) + explainTypes(rtpe, atpe) compatibilityError("type mismatch for %s: %s does not conform to %s".format(slot, abbreviateCoreAliases(rtpe.toString), abbreviateCoreAliases(atpe.toString))) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 15ed784ae0..f1b80d9f1c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -313,8 +313,10 @@ trait Infer extends Checkable { */ ) - def explainTypes(tp1: Type, tp2: Type) = - withDisambiguation(List(), tp1, tp2)(global.explainTypes(tp1, tp2)) + def explainTypes(tp1: Type, tp2: Type) = { + if (context.reportErrors) + withDisambiguation(List(), tp1, tp2)(global.explainTypes(tp1, tp2)) + } /* -- Tests & Checks---------------------------------------------------- */ diff --git a/test/files/neg/abstract-explaintypes.check b/test/files/neg/abstract-explaintypes.check new file mode 100644 index 0000000000..59c1ad2378 --- /dev/null +++ b/test/files/neg/abstract-explaintypes.check @@ -0,0 +1,11 @@ +abstract-explaintypes.scala:6: error: type mismatch; + found : A + required: A.this.T + def foo2: T = bar().baz(); + ^ +abstract-explaintypes.scala:9: error: type mismatch; + found : A + required: A.this.T + def foo5: T = baz().baz(); + ^ +two errors found diff --git a/test/files/neg/abstract-explaintypes.flags b/test/files/neg/abstract-explaintypes.flags new file mode 100644 index 0000000000..b36707c7cf --- /dev/null +++ b/test/files/neg/abstract-explaintypes.flags @@ -0,0 +1 @@ +-explaintypes diff --git a/test/files/neg/abstract-explaintypes.scala b/test/files/neg/abstract-explaintypes.scala new file mode 100644 index 0000000000..f8ecae16fa --- /dev/null +++ b/test/files/neg/abstract-explaintypes.scala @@ -0,0 +1,11 @@ +trait A { + type T <: A; + def baz(): A; + def bar(): T; + def foo1: A = bar().bar(); + def foo2: T = bar().baz(); + def foo3 = bar().baz(); + def foo4: A = baz().bar(); + def foo5: T = baz().baz(); + def foo6 = baz().baz(); +} diff --git a/test/files/pos/t6123-explaintypes-implicits.flags b/test/files/pos/t6123-explaintypes-implicits.flags new file mode 100644 index 0000000000..b36707c7cf --- /dev/null +++ b/test/files/pos/t6123-explaintypes-implicits.flags @@ -0,0 +1 @@ +-explaintypes diff --git a/test/files/pos/t6123-explaintypes-implicits.scala b/test/files/pos/t6123-explaintypes-implicits.scala new file mode 100644 index 0000000000..5242b443d5 --- /dev/null +++ b/test/files/pos/t6123-explaintypes-implicits.scala @@ -0,0 +1,13 @@ +object ImplicitBugReport { + trait Exp[+T] + trait CanBuildExp[-Elem, +To] extends (Exp[Elem] => To) + trait TraversableExp[T, ExpT <: Exp[T]] extends Exp[Traversable[T]] + + implicit def canBuildExp[T]: CanBuildExp[T, Exp[T]] = ??? + implicit def canBuildExpTrav[T, ExpT <: Exp[T]](implicit c: CanBuildExp[T, ExpT]): CanBuildExp[Traversable[T], TraversableExp[T, ExpT]] = ??? + def toExpTempl[T, That](t: T)(implicit c: CanBuildExp[T, That]): That = ??? + + def testBug() { + val a1 = toExpTempl(Seq(1, 2, 3, 5)) + } +} diff --git a/test/files/pos/t6123-explaintypes-macros.flags b/test/files/pos/t6123-explaintypes-macros.flags new file mode 100644 index 0000000000..b36707c7cf --- /dev/null +++ b/test/files/pos/t6123-explaintypes-macros.flags @@ -0,0 +1 @@ +-explaintypes diff --git a/test/files/pos/t6123-explaintypes-macros.scala b/test/files/pos/t6123-explaintypes-macros.scala new file mode 100644 index 0000000000..e650ad2038 --- /dev/null +++ b/test/files/pos/t6123-explaintypes-macros.scala @@ -0,0 +1,7 @@ +import scala.language.experimental.macros +import scala.reflect.macros.Context + +object Macros { + def printf(format: String, params: Any*): Unit = macro printf_impl + def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] = ??? +} |