Hey I’m running into an issue where i’m trying to reference logic but it’s preventing compilation when referencing a generic class that can instantiate itself and is extended by a class that might be referenced as dynamic for logic, as the type might be unknown or a different type than the passed in parameter see below:
import haxe.Constraints.Constructible;
class Test {
static function main() {
var val = new GenericImpl<GenericTest>();
trace("Compiled Successfully");
}
}
@:generic
class GenericImpl<T:Constructible<Void->Void>> extends GenericBase<T>
{
//Commenting out the below line will fix the issue but loses the functionality
public function Logic(reference:GenericImpl<Dynamic>){}
}
@:generic
class GenericBase<T:Constructible<Void->Void>>
{
public function new(){}
public function instantiate():T
{
var instance = new T();
return instance;
}
}
class GenericTest {
public function new(){}
}
fails compilation with error:
Test.hx:21: lines 21-25 : Dynamic has no field new
Any workarounds for this logic, so that i can maintain a reference to the GenericImpl class as either dynamic or something else and maintaining the construction.
Still, I’m curious what are you trying to achieve with this? It looks quite complicated, not just to me, but also apparently to the compiler I suspect this can be done simplier, maybe even without @:generic.
@:generic
class GenericBase<T:Constructible<Void->Void>>
{
public function new(){}
public function instantiate():T
{
var instance = new T();
return instance;
}
@:isVar public var example(get, null):T;
private function get_example():T
{
if (example == null) example = instantiate();
return example;
}
}
Where the example type can be strong typed and decided in a subclass with only cursory restrictions which works, but when factoring the first post where i’m trying to pass around a generic reference it fails
Dynamic has no field new
Edit:
This is a class where you have A extended by B and where a is subclassed by A1, A2 … and B is subclassed by B1, B2, B3 …