From cd4050d27f400723342e4486ac118c7b04b87d5d Mon Sep 17 00:00:00 2001 From: odersky Date: Fri, 9 Dec 2022 17:35:34 +0100 Subject: [PATCH] Don't rely on isProvisional to determine whether atoms computed isProvisional can flip at unpredictable points, so we cannot rely it to be stable between the call to `ensureAtomsComputed` and after it. Fixes #16486 --- compiler/src/dotty/tools/dotc/core/Types.scala | 11 ++++++----- tests/pos/i16486/defs_1.scala | 17 +++++++++++++++++ tests/pos/i16486/usage_2.scala | 4 ++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 tests/pos/i16486/defs_1.scala create mode 100644 tests/pos/i16486/usage_2.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index a076b1580d39..666da728410b 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3441,19 +3441,20 @@ object Types { val tp2w = tp2.widenSingletons if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else TypeComparer.lub(tp1w, tp2w, isSoft = isSoft) - private def ensureAtomsComputed()(using Context): Unit = + private def ensureAtomsComputed()(using Context): Boolean = if atomsRunId != ctx.runId && !isProvisional then myAtoms = computeAtoms() myWidened = computeWidenSingletons() atomsRunId = ctx.runId + true + else + false override def atoms(using Context): Atoms = - ensureAtomsComputed() - if isProvisional then computeAtoms() else myAtoms + if ensureAtomsComputed() then myAtoms else computeAtoms() override def widenSingletons(using Context): Type = - ensureAtomsComputed() - if isProvisional then computeWidenSingletons() else myWidened + if ensureAtomsComputed() then myWidened else computeWidenSingletons() def derivedOrType(tp1: Type, tp2: Type, soft: Boolean = isSoft)(using Context): Type = if ((tp1 eq this.tp1) && (tp2 eq this.tp2) && soft == isSoft) this diff --git a/tests/pos/i16486/defs_1.scala b/tests/pos/i16486/defs_1.scala new file mode 100644 index 000000000000..ea6e303b0975 --- /dev/null +++ b/tests/pos/i16486/defs_1.scala @@ -0,0 +1,17 @@ +// defs_1.scala +import java.time.* + +type Temporal = + java.sql.Date | + LocalDateTime | LocalDate | LocalTime | + Instant + +given Conversion[String | Temporal, JsValue] = ??? + +sealed trait JsValue +case class JsObject(value: Map[String, JsValue]) + +object Json{ + def obj(fields: Tuple2[String, JsValue | Option[JsValue]]* ): JsObject = ??? +} + diff --git a/tests/pos/i16486/usage_2.scala b/tests/pos/i16486/usage_2.scala new file mode 100644 index 000000000000..5c9c50ecd596 --- /dev/null +++ b/tests/pos/i16486/usage_2.scala @@ -0,0 +1,4 @@ +// usage_2.scala +class Bug { + def searchJson = Json.obj("foo" -> "bar") +} \ No newline at end of file