Skip to content

Don't rely on isProvisional to determine whether atoms computed #16489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}