Skip to content

Proposal: Ability to seal trees of classes #8726

@DerpMcDerp

Description

@DerpMcDerp

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:

  1. the class that UnsealedTo is applied on is an immediate parent of all the classes listed
  2. 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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions