HaxeFoundation / HaxeFoundation/haxe

should expected type be propagated through type params

Open
#8,186 4 comments 1 reaction 0 assignees View on GitHub
enhancement type-system
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Sorry, this question was probably asked and discussed before, but I'm in the middle of work atm and can't find the issue.

So consider the following code:
```haxe
extern class Vector {
static function ofArray(v:Array):Vector;
}

class Base {}

class Child extends Base {
public function new() {}
}

class Main {
static function main() {
var v:Vector = Vector.ofArray([new Child()]);
}
}
```

this currently gives:
```
Main.hx:13: characters 3-54 : error: Child should be Base
Main.hx:13: characters 3-54 : have: Vector
Main.hx:13: characters 3-54 : want: Vector
```

which is understandable, as `ofArray` call receives `[new Child()]` with an expected type of just `Array`, so it binds `T` to `Child` and returns `Vector`.

My question is: is it possible (and safe) to actually propagate the expected type through type parameters so the example above compiles?

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.