@@ -79,12 +79,19 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
7979 case SilentResultValue (value) if ! p(value) => SilentTypeError (TypeErrorWrapper (new TypeError (NoPosition , " !p" )))
8080 case _ => this
8181 }
82- @ inline final def orElse [T1 >: T ](f : AbsTypeError => T1 ): T1 = this match {
82+ @ inline final def orElse [T1 >: T ](f : Seq [ AbsTypeError ] => T1 ): T1 = this match {
8383 case SilentResultValue (value) => value
84- case SilentTypeError (err) => f(err )
84+ case s : SilentTypeError => f(s.errors )
8585 }
8686 }
87- case class SilentTypeError (err : AbsTypeError ) extends SilentResult [Nothing ] { }
87+ class SilentTypeError private (val errors : Seq [AbsTypeError ]) extends SilentResult [Nothing ] {
88+ def err : AbsTypeError = errors.head
89+ }
90+ object SilentTypeError {
91+ def apply (errors : AbsTypeError * ): SilentTypeError = new SilentTypeError (errors)
92+ def unapply (error : SilentTypeError ): Option [AbsTypeError ] = error.errors.headOption
93+ }
94+
8895 case class SilentResultValue [+ T ](value : T ) extends SilentResult [T ] { }
8996
9097 def newTyper (context : Context ): Typer = new NormalTyper (context)
@@ -682,14 +689,13 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
682689 context.undetparams = context1.undetparams
683690 context.savedTypeBounds = context1.savedTypeBounds
684691 context.namedApplyBlockInfo = context1.namedApplyBlockInfo
685- context1.firstError match {
686- case Some (err) =>
687- stopStats()
688- SilentTypeError (err)
689- case None =>
690- // If we have a successful result, emit any warnings it created.
691- context1.flushAndIssueWarnings()
692- SilentResultValue (result)
692+ if (context1.hasErrors) {
693+ stopStats()
694+ SilentTypeError (context1.errors: _* )
695+ } else {
696+ // If we have a successful result, emit any warnings it created.
697+ context1.flushAndIssueWarnings()
698+ SilentResultValue (result)
693699 }
694700 } else {
695701 assert(context.bufferErrors || isPastTyper, " silent mode is not available past typer" )
@@ -1258,9 +1264,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
12581264 reportError
12591265 }
12601266
1261- silent(_.adaptToMember(qual, HasMember (name), reportAmbiguous = false )) orElse (err =>
1267+ silent(_.adaptToMember(qual, HasMember (name), reportAmbiguous = false )) orElse (errs =>
12621268 onError {
1263- if (reportAmbiguous) context issue err
1269+ if (reportAmbiguous) errs foreach ( context issue _)
12641270 setError(tree)
12651271 }
12661272 )
@@ -3786,7 +3792,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
37863792 }
37873793 }
37883794 }
3789- def wrapErrors (tree : Tree , typeTree : Typer => Tree ): Tree = silent(typeTree) orElse (err => DynamicRewriteError (tree, err))
3795+ def wrapErrors (tree : Tree , typeTree : Typer => Tree ): Tree = silent(typeTree) orElse (err => DynamicRewriteError (tree, err.head ))
37903796 }
37913797
37923798 def typed1 (tree : Tree , mode : Mode , pt : Type ): Tree = {
@@ -4173,7 +4179,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
41734179 def tryTypedApply (fun : Tree , args : List [Tree ]): Tree = {
41744180 val start = if (Statistics .canEnable) Statistics .startTimer(failedApplyNanos) else null
41754181
4176- def onError (typeError : AbsTypeError ): Tree = {
4182+ def onError (typeErrors : Seq [ AbsTypeError ] ): Tree = {
41774183 if (Statistics .canEnable) Statistics .stopTimer(failedApplyNanos, start)
41784184
41794185 // If the problem is with raw types, copnvert to existentials and try again.
@@ -4198,13 +4204,13 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
41984204 case TypeApply (fun, args) => treesInResult(fun) ++ args.flatMap(treesInResult)
41994205 case _ => Nil
42004206 })
4201- def errorInResult (tree : Tree ) = treesInResult(tree) exists (_.pos == typeError.errPos )
4207+ def errorInResult (tree : Tree ) = treesInResult(tree) exists (err => typeErrors.exists(_.errPos == err.pos) )
42024208
4203- val retry = (typeError. errPos != null ) && (fun :: tree :: args exists errorInResult)
4209+ val retry = (typeErrors.forall(_. errPos != null ) ) && (fun :: tree :: args exists errorInResult)
42044210 typingStack.printTyping({
42054211 val funStr = ptTree(fun) + " and " + (args map ptTree mkString " , " )
42064212 if (retry) " second try: " + funStr
4207- else " no second try: " + funStr + " because error not in result: " + typeError .errPos+ " !=" + tree.pos
4213+ else " no second try: " + funStr + " because error not in result: " + typeErrors.head .errPos+ " !=" + tree.pos
42084214 })
42094215 if (retry) {
42104216 val Select (qual, name) = fun
@@ -4220,7 +4226,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
42204226 case _ => ()
42214227 }
42224228 }
4223- issue(typeError)
4229+ typeErrors foreach issue
42244230 setError(treeCopy.Apply (tree, fun, args))
42254231 }
42264232
0 commit comments