Skip to content

Type capability modifiers #2242

Closed
Closed
@munificent

Description

@munificent

EDITED: After quite a bit of discussion, a proposal based off of the description below (but with some different choices in syntax) has been accepted here.

Users have asked for the ability to prevent a class from being extended (#987) and/or implemented (#704). For exhaustiveness checks in pattern matching, we also need the ability to define a type with a known closed set of subtypes.

The Type Modifiers proposal addresses those. It's an alternative to the earlier Packaged Libraries proposal. The very brief summary is:

  • Remove the ability to use a class as a mixin (Do not allow mixing in a class, with migration path #1643).
  • Types default to fully permissive as they are today.
  • Use closed on a class to disable extending it.
  • Use base on a class or mixin to disables its implicit interface.
  • Use a switch modifier on a class or mixin to defines the root of a sealed type family for exhaustiveness checking. It also implies abstract.

This issue is to discuss the proposal. Feel free to file other more specific issues too.

Metadata

Metadata

Assignees

Labels

class-modifiersIssues related to "base", "final", "interface", and "mixin" modifiers on classes and mixins.featureProposed language feature that solves one or more problems

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions