Skip to content

Commit

Permalink
Don't rely on isProvisional to determine whether atoms computed (#16489)
Browse files Browse the repository at this point in the history
Fixes #16486
  • Loading branch information
dwijnand authored Dec 12, 2022
2 parents 231f9ab + cd4050d commit a4a1cbc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/i16486/defs_1.scala
Original file line number Diff line number Diff line change
@@ -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 = ???
}

4 changes: 4 additions & 0 deletions tests/pos/i16486/usage_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// usage_2.scala
class Bug {
def searchJson = Json.obj("foo" -> "bar")
}

0 comments on commit a4a1cbc

Please sign in to comment.