Skip to content

Commit cd4050d

Browse files
committed
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
1 parent 716d93d commit cd4050d

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,19 +3441,20 @@ object Types {
34413441
val tp2w = tp2.widenSingletons
34423442
if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else TypeComparer.lub(tp1w, tp2w, isSoft = isSoft)
34433443

3444-
private def ensureAtomsComputed()(using Context): Unit =
3444+
private def ensureAtomsComputed()(using Context): Boolean =
34453445
if atomsRunId != ctx.runId && !isProvisional then
34463446
myAtoms = computeAtoms()
34473447
myWidened = computeWidenSingletons()
34483448
atomsRunId = ctx.runId
3449+
true
3450+
else
3451+
false
34493452

34503453
override def atoms(using Context): Atoms =
3451-
ensureAtomsComputed()
3452-
if isProvisional then computeAtoms() else myAtoms
3454+
if ensureAtomsComputed() then myAtoms else computeAtoms()
34533455

34543456
override def widenSingletons(using Context): Type =
3455-
ensureAtomsComputed()
3456-
if isProvisional then computeWidenSingletons() else myWidened
3457+
if ensureAtomsComputed() then myWidened else computeWidenSingletons()
34573458

34583459
def derivedOrType(tp1: Type, tp2: Type, soft: Boolean = isSoft)(using Context): Type =
34593460
if ((tp1 eq this.tp1) && (tp2 eq this.tp2) && soft == isSoft) this

tests/pos/i16486/defs_1.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// defs_1.scala
2+
import java.time.*
3+
4+
type Temporal =
5+
java.sql.Date |
6+
LocalDateTime | LocalDate | LocalTime |
7+
Instant
8+
9+
given Conversion[String | Temporal, JsValue] = ???
10+
11+
sealed trait JsValue
12+
case class JsObject(value: Map[String, JsValue])
13+
14+
object Json{
15+
def obj(fields: Tuple2[String, JsValue | Option[JsValue]]* ): JsObject = ???
16+
}
17+

tests/pos/i16486/usage_2.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// usage_2.scala
2+
class Bug {
3+
def searchJson = Json.obj("foo" -> "bar")
4+
}

0 commit comments

Comments
 (0)