-
-
Notifications
You must be signed in to change notification settings - Fork 694
Open
Description
i have this small class:
package geom;
@:generic class Vec<T, @:const L:Int> {
public var data:Array<T>;
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<Float, 4> = 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels