HaxeFoundation / HaxeFoundation/haxe

@:const type parameters on @:generic classes being unstable

Open
#12,652 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

i have this small class:

package geom;

```
@:generic class Vec {
public var data:Array;
public function new(...values:T) {
if (values.length > L) throw "Too many values for Vec of length " + L;
data = [];
for (i in 0...L) data.push(values[i]);
}
}
```

no IDE errors, using --interp, this should allow me to use it like

` var vec:Vec = new Vec(5, 4, 8, 10);`

but it's really unstable as this example gives this error when i run it

`source/geom/Vec.hx:6: characters 26-27 : Only Const type parameters can be used as value`

weird things is this:

```
public function new(...values:T) {
// doesnt give an error
if (values.length > L) throw "Too many values for Vec of length " + L;
// data = [];
// for (i in 0...L) data.push(values[i]);
}
```
```
public function new(...values:T) {
// DOES give that same error
if (values.length > L) throw "Too many values for Vec of length " + L;
data = [];
// for (i in 0...L) data.push(values[i]);
}
```
```
public function new(...values:T) {
// no error
// if (values.length > L) throw "Too many values for Vec of length " + L;
data = [];
// for (i in 0...L) data.push(values[i]);
}
```
```
public function new(...values:T) {
// error
// if (values.length > L) throw "Too many values for Vec of length " + L;
// data = [];
for (i in 0...L) data.push(values[i]);
}
```
and the rest of the combinations all give the same error, i tried going something like this

```
public function new(...values:T) {
var length:Int = L;
if (values.length > length) throw "Too many values for Vec of length " + length;
data = [];
for (i in 0...length) data.push(values[i]);
}
```
but it results to the exact same thing

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.