From 83feb8609161bf19247a8a310f8c5a9e3d8469f5 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 8 Oct 2013 22:28:00 +0200 Subject: SI-7985 Typecheck args after failure to typecheck function `missing1.foo(missing2)` now reports `missing1` and `missing2` as not found. Previously, only the first was reported. The arguments are typed with an expected type ErrorType. We propagate this through as the inferred type of anonymous function parameters to avoid issuing cascading "missing parameter type" errors in code like: scala> Nil.mapp(x => abracadabra) :8: error: value mapp is not a member of object Nil Nil.mapp(x => abracadabra) ^ :8: error: not found: value abracadabra Nil.mapp(x => abracadabra) ^ This was in response to unwanted changes in the output of existing neg tests; no new test is added. Similarly, we refine the errors in neg/t6436b.scala by to avoid cascaded errors after: type mismatch; found: StringContext, required: ?{def q: ?} --- .../scala/tools/nsc/typechecker/Typers.scala | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 0e4797d011..7bf342f475 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -81,14 +81,20 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } @inline final def orElse[T1 >: T](f: Seq[AbsTypeError] => T1): T1 = this match { case SilentResultValue(value) => value - case s : SilentTypeError => f(s.errors) + case s : SilentTypeError => f(s.reportableErrors) } } - class SilentTypeError private(val errors: Seq[AbsTypeError]) extends SilentResult[Nothing] { + class SilentTypeError private(val errors: List[AbsTypeError]) extends SilentResult[Nothing] { def err: AbsTypeError = errors.head + def reportableErrors = errors match { + case (e1: AmbiguousImplicitTypeError) +: _ => + List(e1) // DRYer error reporting for neg/t6436b.scala + case all => + all + } } object SilentTypeError { - def apply(errors: AbsTypeError*): SilentTypeError = new SilentTypeError(errors) + def apply(errors: AbsTypeError*): SilentTypeError = new SilentTypeError(errors.toList) def unapply(error: SilentTypeError): Option[AbsTypeError] = error.errors.headOption } @@ -2714,7 +2720,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val FunctionSymbol = FunctionClass(numVparams) val (argpts, respt) = pt baseType FunctionSymbol match { case TypeRef(_, FunctionSymbol, args :+ res) => (args, res) - case _ => (fun.vparams map (_ => NoType), WildcardType) + case _ => (fun.vparams map (_ => if (pt == ErrorType) ErrorType else NoType), WildcardType) } if (argpts.lengthCompare(numVparams) != 0) WrongNumberOfParametersError(fun, argpts) @@ -4278,8 +4284,12 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper tryTypedApply(fun2, args) else doTypedApply(tree, fun2, args, mode, pt) - case SilentTypeError(err) => - onError({ issue(err); setError(tree) }) + case err: SilentTypeError => + onError({ + err.reportableErrors foreach issue + args foreach (arg => typed(arg, mode, ErrorType)) + setError(tree) + }) } } -- cgit v1.2.3