@@ -35,40 +35,13 @@ trait Typers {
3535
3636 def inferImplicitValue (pt : Type , silent : Boolean = true , withMacrosDisabled : Boolean = false , pos : Position = enclosingPosition): Tree = {
3737 macroLogVerbose(" inferring implicit value of type %s, macros = %s" .format(pt, ! withMacrosDisabled))
38- inferImplicit(universe.EmptyTree , pt, isView = false , silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos)
38+ universe.analyzer. inferImplicit(universe.EmptyTree , pt, false , callsiteTyper.context, silent, withMacrosDisabled, pos, ( pos, msg) => throw TypecheckException ( pos, msg) )
3939 }
4040
4141 def inferImplicitView (tree : Tree , from : Type , to : Type , silent : Boolean = true , withMacrosDisabled : Boolean = false , pos : Position = enclosingPosition): Tree = {
4242 macroLogVerbose(" inferring implicit view from %s to %s for %s, macros = %s" .format(from, to, tree, ! withMacrosDisabled))
4343 val viewTpe = universe.appliedType(universe.definitions.FunctionClass (1 ).toTypeConstructor, List (from, to))
44- inferImplicit(tree, viewTpe, isView = true , silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos)
45- }
46-
47- private def inferImplicit (tree : Tree , pt : Type , isView : Boolean , silent : Boolean , withMacrosDisabled : Boolean , pos : Position ): Tree = {
48- import universe .analyzer .SearchResult
49- import scala .tools .nsc .typechecker .DivergentImplicit
50- val context = callsiteTyper.context
51- val wrapper1 = if (! withMacrosDisabled) (context.withMacrosEnabled[SearchResult ] _) else (context.withMacrosDisabled[SearchResult ] _)
52- def wrapper (inference : => SearchResult ) = wrapper1(inference)
53- def fail (reason : Option [String ]) = {
54- macroLogVerbose(" implicit search has failed. to find out the reason, turn on -Xlog-implicits" )
55- if (! silent) {
56- if (context.hasErrors) throw new TypecheckException (context.errBuffer.head.errPos, context.errBuffer.head.errMsg)
57- else throw new TypecheckException (pos, reason getOrElse " implicit search has failed. to find out the reason, turn on -Xlog-implicits" )
58- }
59- universe.EmptyTree
60- }
61- try {
62- wrapper(universe.analyzer.inferImplicit(tree, pt, reportAmbiguous = true , isView = isView, context = context, saveAmbiguousDivergent = ! silent, pos = pos)) match {
63- case failure if failure.tree.isEmpty => fail(None )
64- case success => success.tree
65- }
66- } catch {
67- case ex : DivergentImplicit =>
68- if (universe.settings.Xdivergence211 .value)
69- universe.debuglog(" this shouldn't happen. DivergentImplicit exception has been thrown with -Xdivergence211 turned on: " + ex)
70- fail(Some (" divergent implicit expansion" ))
71- }
44+ universe.analyzer.inferImplicit(tree, viewTpe, true , callsiteTyper.context, silent, withMacrosDisabled, pos, (pos, msg) => throw TypecheckException (pos, msg))
7245 }
7346
7447 def resetAllAttrs (tree : Tree ): Tree = universe.resetAllAttrs(tree)
0 commit comments