@@ -13,24 +13,19 @@ import printing._
1313import scala .annotation .internal .sharable
1414
1515object GadtConstraint :
16- @ sharable val empty =
17- new GadtConstraint (OrderingConstraint .empty, SimpleIdentityMap .empty, SimpleIdentityMap .empty, false )
16+ @ sharable val empty : GadtConstraint =
17+ new ProperGadtConstraint (OrderingConstraint .empty, SimpleIdentityMap .empty, SimpleIdentityMap .empty, false )
1818
1919/** Represents GADT constraints currently in scope */
20- final class GadtConstraint private (
20+ sealed trait GadtConstraint (
2121 private var myConstraint : Constraint ,
2222 private var mapping : SimpleIdentityMap [Symbol , TypeVar ],
2323 private var reverseMapping : SimpleIdentityMap [TypeParamRef , Symbol ],
2424 private var wasConstrained : Boolean
25- ) extends ConstraintHandling with Showable {
26- import dotty . tools . dotc . config . Printers .{ gadts , gadtsConstr }
25+ ) extends Showable {
26+ this : ConstraintHandling =>
2727
28- def this () = this (
29- myConstraint = new OrderingConstraint (SimpleIdentityMap .empty, SimpleIdentityMap .empty, SimpleIdentityMap .empty, SimpleIdentitySet .empty),
30- mapping = SimpleIdentityMap .empty,
31- reverseMapping = SimpleIdentityMap .empty,
32- wasConstrained = false
33- )
28+ import dotty .tools .dotc .config .Printers .{gadts , gadtsConstr }
3429
3530 /** Exposes ConstraintHandling.subsumes */
3631 def subsumes (left : GadtConstraint , right : GadtConstraint , pre : GadtConstraint )(using Context ): Boolean = {
@@ -195,7 +190,7 @@ final class GadtConstraint private(
195190
196191 def symbols : List [Symbol ] = mapping.keys
197192
198- def fresh : GadtConstraint = new GadtConstraint (myConstraint, mapping, reverseMapping, wasConstrained)
193+ def fresh : GadtConstraint = new ProperGadtConstraint (myConstraint, mapping, reverseMapping, wasConstrained)
199194
200195 /** Restore the state from other [[GadtConstraint ]], probably copied using [[fresh ]] */
201196 def restore (other : GadtConstraint ): Unit =
@@ -263,3 +258,10 @@ final class GadtConstraint private(
263258 /** Provides more information than toText, by showing the underlying Constraint details. */
264259 def debugBoundsDescription (using Context ): String = i " $this\n $constraint"
265260}
261+
262+ private class ProperGadtConstraint (
263+ myConstraint : Constraint ,
264+ mapping : SimpleIdentityMap [Symbol , TypeVar ],
265+ reverseMapping : SimpleIdentityMap [TypeParamRef , Symbol ],
266+ wasConstrained : Boolean ,
267+ ) extends ConstraintHandling with GadtConstraint (myConstraint, mapping, reverseMapping, wasConstrained)
0 commit comments