HaxeFoundation / HaxeFoundation/haxe

support covariance for abstracts

Open
#9,611 4 comments 6 reactions 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.