@@ -13,24 +13,19 @@ import printing._
13
13
import scala .annotation .internal .sharable
14
14
15
15
object 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 )
18
18
19
19
/** Represents GADT constraints currently in scope */
20
- final class GadtConstraint private (
20
+ sealed trait GadtConstraint (
21
21
private var myConstraint : Constraint ,
22
22
private var mapping : SimpleIdentityMap [Symbol , TypeVar ],
23
23
private var reverseMapping : SimpleIdentityMap [TypeParamRef , Symbol ],
24
24
private var wasConstrained : Boolean
25
- ) extends ConstraintHandling with Showable {
26
- import dotty . tools . dotc . config . Printers .{ gadts , gadtsConstr }
25
+ ) extends Showable {
26
+ this : ConstraintHandling =>
27
27
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 }
34
29
35
30
/** Exposes ConstraintHandling.subsumes */
36
31
def subsumes (left : GadtConstraint , right : GadtConstraint , pre : GadtConstraint )(using Context ): Boolean = {
@@ -195,7 +190,7 @@ final class GadtConstraint private(
195
190
196
191
def symbols : List [Symbol ] = mapping.keys
197
192
198
- def fresh : GadtConstraint = new GadtConstraint (myConstraint, mapping, reverseMapping, wasConstrained)
193
+ def fresh : GadtConstraint = new ProperGadtConstraint (myConstraint, mapping, reverseMapping, wasConstrained)
199
194
200
195
/** Restore the state from other [[GadtConstraint ]], probably copied using [[fresh ]] */
201
196
def restore (other : GadtConstraint ): Unit =
@@ -263,3 +258,10 @@ final class GadtConstraint private(
263
258
/** Provides more information than toText, by showing the underlying Constraint details. */
264
259
def debugBoundsDescription (using Context ): String = i " $this\n $constraint"
265
260
}
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