Skip to content

Commit

Permalink
Avoid sharing a mutable empty GadtConstraint!
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 17, 2022
1 parent 4e8a1a6 commit 2177a2a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ object Contexts {
.updated(notNullInfosLoc, Nil)
.updated(compilationUnitLoc, NoCompilationUnit)
searchHistory = new SearchRoot
gadt = GadtConstraint.empty
gadt = GadtConstraint()
}

@sharable object NoContext extends Context((null: ContextBase | Null).uncheckedNN) {
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import util.{SimpleIdentitySet, SimpleIdentityMap}
import collection.mutable
import printing._

import scala.annotation.internal.sharable

object GadtConstraint:
@sharable val empty: GadtConstraint =
def apply(): GadtConstraint =
new ProperGadtConstraint(OrderingConstraint.empty, SimpleIdentityMap.empty, SimpleIdentityMap.empty, false)

/** Represents GADT constraints currently in scope */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3774,7 +3774,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
adaptToSubType(wtp)
case CompareResult.OKwithGADTUsed
if pt.isValueType
&& !inContext(ctx.fresh.setGadt(GadtConstraint.empty)) {
&& !inContext(ctx.fresh.setGadt(GadtConstraint())) {
val res = (tree.tpe.widenExpr frozen_<:< pt)
if res then
// we overshot; a cast is not needed, after all.
Expand Down

0 comments on commit 2177a2a

Please sign in to comment.