From 3f544e15b798094d36c5ce3758bf08db20ce0abc Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 22 Aug 2022 17:52:22 +0200 Subject: [PATCH 1/2] Fix swapKey Fixes #15845. Curiously this code was never exercised before, despite the many millions of lines of code we compile. It's even more curious that the faulty behavior could be triggered by such a simple example. --- .../dotty/tools/dotc/core/OrderingConstraint.scala | 4 +++- tests/pos/i15845/State.scala | 11 +++++++++++ tests/pos/i15845/state/Config.scala | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i15845/State.scala create mode 100644 tests/pos/i15845/state/Config.scala diff --git a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala index a304fa9f5705..ed04145c1d02 100644 --- a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala @@ -498,7 +498,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds, (this.typeVarOfParam(tl.paramRefs(0)) ne that.typeVarOfParam(tl.paramRefs(0))) def subst(from: TypeLambda, to: TypeLambda)(using Context): OrderingConstraint = - def swapKey[T](m: ArrayValuedMap[T]) = m.remove(from).updated(to, m(from).nn) + def swapKey[T](m: ArrayValuedMap[T]) = + val info = m(from) + if info == null then m else m.remove(from).updated(to, info) var current = newConstraint(swapKey(boundsMap), swapKey(lowerMap), swapKey(upperMap)) def subst[T <: Type](x: T): T = x.subst(from, to).asInstanceOf[T] current.foreachParam {(p, i) => diff --git a/tests/pos/i15845/State.scala b/tests/pos/i15845/State.scala new file mode 100644 index 000000000000..ed907b7e899e --- /dev/null +++ b/tests/pos/i15845/State.scala @@ -0,0 +1,11 @@ +package config + +import state._ + +object State { + + object Info { + def apply(): Info = Info(Config(), Seq.empty) + } + case class Info(cfg: AnyRef, allTypes: Seq[AnyRef]) +} diff --git a/tests/pos/i15845/state/Config.scala b/tests/pos/i15845/state/Config.scala new file mode 100644 index 000000000000..4b0e11d7d191 --- /dev/null +++ b/tests/pos/i15845/state/Config.scala @@ -0,0 +1,4 @@ +package config +package state + +case class Config(simulations: Seq[(String, Any)] = Seq.empty) From 6a74d4dea8ee03bbabe2de9f4e244d1d33bb528b Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 22 Aug 2022 18:05:58 +0200 Subject: [PATCH 2/2] Fix test directory --- tests/pos/i15845/{ => config}/State.scala | 0 tests/pos/i15845/{ => config}/state/Config.scala | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/pos/i15845/{ => config}/State.scala (100%) rename tests/pos/i15845/{ => config}/state/Config.scala (100%) diff --git a/tests/pos/i15845/State.scala b/tests/pos/i15845/config/State.scala similarity index 100% rename from tests/pos/i15845/State.scala rename to tests/pos/i15845/config/State.scala diff --git a/tests/pos/i15845/state/Config.scala b/tests/pos/i15845/config/state/Config.scala similarity index 100% rename from tests/pos/i15845/state/Config.scala rename to tests/pos/i15845/config/state/Config.scala