Skip to content

Commit 2177a2a

Browse files
committed
Avoid sharing a mutable empty GadtConstraint!
1 parent 4e8a1a6 commit 2177a2a

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ object Contexts {
814814
.updated(notNullInfosLoc, Nil)
815815
.updated(compilationUnitLoc, NoCompilationUnit)
816816
searchHistory = new SearchRoot
817-
gadt = GadtConstraint.empty
817+
gadt = GadtConstraint()
818818
}
819819

820820
@sharable object NoContext extends Context((null: ContextBase | Null).uncheckedNN) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import util.{SimpleIdentitySet, SimpleIdentityMap}
1010
import collection.mutable
1111
import printing._
1212

13-
import scala.annotation.internal.sharable
14-
1513
object GadtConstraint:
16-
@sharable val empty: GadtConstraint =
14+
def apply(): GadtConstraint =
1715
new ProperGadtConstraint(OrderingConstraint.empty, SimpleIdentityMap.empty, SimpleIdentityMap.empty, false)
1816

1917
/** Represents GADT constraints currently in scope */

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3774,7 +3774,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
37743774
adaptToSubType(wtp)
37753775
case CompareResult.OKwithGADTUsed
37763776
if pt.isValueType
3777-
&& !inContext(ctx.fresh.setGadt(GadtConstraint.empty)) {
3777+
&& !inContext(ctx.fresh.setGadt(GadtConstraint())) {
37783778
val res = (tree.tpe.widenExpr frozen_<:< pt)
37793779
if res then
37803780
// we overshot; a cast is not needed, after all.

0 commit comments

Comments
 (0)