Skip to content

Commit

Permalink
Merge pull request scala#12827 from dotty-staging/skip-already-committed
Browse files Browse the repository at this point in the history
Fix TyperState assertion failures
  • Loading branch information
odersky authored Jun 15, 2021
2 parents 08065ed + ea6449f commit 16e07f4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ object Contexts {
final def withOwner(owner: Symbol): Context =
if (owner ne this.owner) fresh.setOwner(owner) else this

final def withUncommittedTyperState: Context =
val ts = typerState.uncommittedAncestor
if ts ne typerState then fresh.setTyperState(ts) else this

final def withProperty[T](key: Key[T], value: Option[T]): Context =
if (property(key) == value) this
else value match {
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TyperState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ class TyperState() {
*/
def commit()(using Context): Unit = {
Stats.record("typerState.commit")
assert(isCommittable)
assert(isCommittable, s"$this is not committable")
assert(!isCommitted, s"$this is already committed")
reporter.flush()
setCommittable(false)
val targetState = ctx.typerState
assert(!targetState.isCommitted, s"Attempt to commit $this into already committed $targetState")
if constraint ne targetState.constraint then
Stats.record("typerState.commit.new constraint")
constr.println(i"committing $this to $targetState, fromConstr = $constraint, toConstr = ${targetState.constraint}")
Expand All @@ -150,7 +153,6 @@ class TyperState() {
else
targetState.mergeConstraintWith(this)
targetState.gc()
reporter.flush()
isCommitted = true
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ object ProtoTypes {
if state.typedArgs.size == args.length then state.typedArgs
else
val passedTyperState = ctx.typerState
inContext(protoCtx) {
val protoTyperState = protoCtx.typerState
inContext(protoCtx.withUncommittedTyperState) {
val protoTyperState = ctx.typerState
val oldConstraint = protoTyperState.constraint
val args1 = args.mapWithIndexConserve((arg, idx) =>
cacheTypedArg(arg, arg => typer.typed(norm(arg, idx)), force = false))
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i12736a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Test {
def apply[S](r: Any): Any = r

def test =
(x: Int) => Test(doesntexist, x) // error
}
6 changes: 6 additions & 0 deletions tests/neg/i12736b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Test {
def apply[S](r: Any)(using DoesntExist): Any = r // error

def test(o: Option[Any]) =
o.map(x => Test(doesntExist, x)) // error
}

0 comments on commit 16e07f4

Please sign in to comment.