Skip to content

Commit 3664854

Browse files
committed
Handle complex context merging cases
Test case in isApplicableSafe.scala. It turns out that this requires a context merge using the new `&' operator. Sequence of actions: 1) Typecheck argument in typerstate 1. 2) Cache argument. 3) Evolve same typer state (to typecheck other arguments, say) leading to a different constraint. 4) Take typechecked argument in same state. It turns out that the merge in TyperState is needed not just for isApplicableSafe but also for (e.g. erased-lubs.scala) as well as many parts of dotty itself.
1 parent eef9be9 commit 3664854

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/dotty/tools/dotc/core/TyperState.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ extends TyperState(r) {
9696

9797
override def reporter = myReporter
9898

99-
private var myConstraint: Constraint = previous.constraint
99+
private val previousConstraint = previous.constraint
100+
private var myConstraint: Constraint = previousConstraint
100101

101102
override def constraint = myConstraint
102103
override def constraint_=(c: Constraint)(implicit ctx: Context) = {
@@ -129,8 +130,9 @@ extends TyperState(r) {
129130
override def commit()(implicit ctx: Context) = {
130131
val targetState = ctx.typerState
131132
assert(isCommittable)
132-
if (targetState eq previous) targetState.constraint = constraint
133-
else targetState.constraint &= constraint
133+
targetState.constraint =
134+
if (targetState.constraint eq previousConstraint) constraint
135+
else targetState.constraint & constraint
134136
constraint foreachTypeVar { tvar =>
135137
if (tvar.owningState eq this)
136138
tvar.owningState = targetState

src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ object Inferencing {
7878
def apply(x: Boolean, tp: Type): Boolean = tp.dealias match {
7979
case _: WildcardType | _: ProtoType =>
8080
false
81-
case tvar: TypeVar if !tvar.isInstantiated =>
81+
case tvar: TypeVar
82+
if !tvar.isInstantiated && ctx.typerState.constraint.contains(tvar) =>
8283
force.appliesTo(tvar) && {
8384
val direction = instDirection(tvar.origin)
8485
if (direction != 0) {

0 commit comments

Comments
 (0)