@@ -346,7 +346,7 @@ object Implicits {
346
346
* @param level The level where the reference was found
347
347
* @param tstate The typer state to be committed if this alternative is chosen
348
348
*/
349
- case class SearchSuccess (tree : Tree , ref : TermRef , level : Int )(val tstate : TyperState ) extends SearchResult with Showable
349
+ case class SearchSuccess (tree : Tree , ref : TermRef , level : Int )(val tstate : TyperState , val gstate : GADTMap ) extends SearchResult with Showable
350
350
351
351
/** A failed search */
352
352
case class SearchFailure (tree : Tree ) extends SearchResult {
@@ -904,6 +904,7 @@ trait Implicits { self: Typer =>
904
904
result0 match {
905
905
case result : SearchSuccess =>
906
906
result.tstate.commit()
907
+ ctx.gadt.restore(result.gstate)
907
908
implicits.println(i " success: $result" )
908
909
implicits.println(i " committing ${result.tstate.constraint} yielding ${ctx.typerState.constraint} in ${ctx.typerState}" )
909
910
result
@@ -1028,7 +1029,7 @@ trait Implicits { self: Typer =>
1028
1029
val generated2 =
1029
1030
if (cand.isExtension) Applications .ExtMethodApply (generated1).withType(generated1.tpe)
1030
1031
else generated1
1031
- SearchSuccess (generated2, ref, cand.level)(ctx.typerState)
1032
+ SearchSuccess (generated2, ref, cand.level)(ctx.typerState, ctx.gadt )
1032
1033
}
1033
1034
}}
1034
1035
@@ -1040,7 +1041,8 @@ trait Implicits { self: Typer =>
1040
1041
SearchFailure (new DivergingImplicit (cand.ref, pt.widenExpr, argument))
1041
1042
else {
1042
1043
val history = ctx.searchHistory.nest(cand, pt)
1043
- val result = typedImplicit(cand, contextual)(nestedContext().setNewTyperState().setSearchHistory(history))
1044
+ val result =
1045
+ typedImplicit(cand, contextual)(nestedContext().setNewTyperState().setFreshGADTBounds.setSearchHistory(history))
1044
1046
result match {
1045
1047
case res : SearchSuccess =>
1046
1048
ctx.searchHistory.defineBynameImplicit(pt.widenExpr, res)
@@ -1142,7 +1144,9 @@ trait Implicits { self: Typer =>
1142
1144
result match {
1143
1145
case _ : SearchFailure =>
1144
1146
SearchSuccess (ref(defn.Not_value ), defn.Not_value .termRef, 0 )(
1145
- ctx.typerState.fresh().setCommittable(true ))
1147
+ ctx.typerState.fresh().setCommittable(true ),
1148
+ ctx.gadt
1149
+ )
1146
1150
case _ : SearchSuccess =>
1147
1151
NoMatchingImplicitsFailure
1148
1152
}
@@ -1212,7 +1216,7 @@ trait Implicits { self: Typer =>
1212
1216
// other candidates need to be considered.
1213
1217
ctx.searchHistory.recursiveRef(pt) match {
1214
1218
case ref : TermRef =>
1215
- SearchSuccess (tpd.ref(ref).withPos(pos.startPos), ref, 0 )(ctx.typerState)
1219
+ SearchSuccess (tpd.ref(ref).withPos(pos.startPos), ref, 0 )(ctx.typerState, ctx.gadt )
1216
1220
case _ =>
1217
1221
val eligible =
1218
1222
if (contextual) ctx.implicits.eligible(wildProto)
@@ -1452,7 +1456,7 @@ final class SearchRoot extends SearchHistory {
1452
1456
implicitDictionary.get(tpe) match {
1453
1457
case Some ((ref, _)) =>
1454
1458
implicitDictionary.put(tpe, (ref, result.tree))
1455
- SearchSuccess (tpd.ref(ref).withPos(result.tree.pos), result.ref, result.level)(result.tstate)
1459
+ SearchSuccess (tpd.ref(ref).withPos(result.tree.pos), result.ref, result.level)(result.tstate, result.gstate )
1456
1460
case None => result
1457
1461
}
1458
1462
}
@@ -1553,7 +1557,7 @@ final class SearchRoot extends SearchHistory {
1553
1557
1554
1558
val blk = Block (classDef :: inst :: Nil , res)
1555
1559
1556
- success.copy(tree = blk)(success.tstate)
1560
+ success.copy(tree = blk)(success.tstate, success.gstate )
1557
1561
}
1558
1562
}
1559
1563
}
0 commit comments