-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider allowing extension types to implement non super type #54295
Comments
If extension types are compile time only, then they cannot soundly be allowed to implement any interface that their representation object doesn't implement. Extension types are not able to implement union types, because they are erased at runtime, and there are no union types they can be erased to which are still sound. |
Agreeing with @lrhn, I'd like to add a little bit of background information. @Zekfad wrote:
I guess you meant dart-lang/language#2727? Thanks for catching that! The A clause like The crucial difference between the old proposals where // According to old rules.
void main() {
IdNumber id = ...;
Comparable<IdNumber> comp = id; // Compile-time error!
} In the old proposals, // Modified example, using current rules.
extension type IdNumber(int i) implements Comparable<num> {
bool operator <(IdNumber other) => i < other.i;
int compareTo(IdNumber other) => i - other.i;
bool verify({required int age}) => true; // TODO: Implement.
}
void main() {
IdNumber id = ...;
Comparable<num> comp = id; // OK!
} Note that When there is an actual subtype relationship, it must be sound to have a situation where the value of a variable like In the current specification, So, lots of things happened with |
Currently extension types can only "implement" super type of representation or representation type itself.
This renders example at https://github.com/dart-lang/sdk#2727 as invalid.
I think this restricts a powerful tool to just a way to hide members from a type, other than that it seems more like a simple extension.
Most obvious usage if restriction would be lifted is to use sealed hierarchy to achieve compile-only union of different types with full static analysis rather than
dynamic
.The text was updated successfully, but these errors were encountered: