HaxeFoundation / HaxeFoundation/haxe
support covariance for abstracts
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
I know variance a big and confusing topic, but since we allow covariance for structures (e.g. passing `Array` as `Iterable`), maybe we could also allow it for abstracts (to pass `Array` to `ReadOnlyArray`)? Also ideally we would treat interfaces just like structs wrt variance.
```haxe
class Parent {
public function new() {}
}
class Child extends Parent {}
function withStruct(arr:Iterable) {}
function withAbstract(arr:haxe.ds.ReadOnlyArray) {}
function main() {
// this works
withStruct(new Array());
// this doesn't
withAbstract(new Array());
}
```
I guess the biggest challenge here is to tame target native compilers?
Contributor guide
Assessment
This issue has not been assessed yet.