-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Description
If you have a tree of classes, e.g.
Object
Atom
Cons
Number
Integer
FixInt
BigInt
Rational
BigRat
Approx
Float
Double
Lambda
C# only lets you seal the leaves of the hiearchy, i.e. Atom, Cons, FixInt, BigInt, BigRat Float, Double, Lambda.
Number, Integer, Rational, and Approx are (currently) required to be unsealed. It would be better if there was a way to make them sealed as well. Something like the following could let you do that:
[UnsealedTo(Integer, Rational)]
public sealed class Number {
...
}
[UnsealedTo(FixInt, BigInt)]
public sealed class Integer {
...
}
[UnsealedTo(BigRat, Approx)]
public sealed class Rational {
...
}
[UnsealedTo(Float, Double)]
public sealed class Approx {
...
}
UnsealedToAttribute lets you list which classes the compiler allows you to treat as if it were unsealed. This gives us the ability to seal trees of classes rather than just the leaves.
The compiler should verify that:
- the class that
UnsealedTois applied on is an immediate parent of all the classes listed - the classes listed are all
sealed
There should also be a Type.IsSealedLeaf property to distinguish between sealed leaves and uses of the sealed keyword (i.e. Type.IsSealedLeaf should be a subset of Type.IsSealed).
Reactions are currently unavailable