COMMUNITY

Inline with type parameters

Can someone explain why I cannot inline a method call from the superclass when using the type parameter?

class Event {}

class Dispatcher<TEvent:Event> {
	private function dispatchObject(event:TEvent) {}
}

class SomeEvent extends Event {
	public function new() {}
}

class SomeDispatcher extends Dispatcher<SomeEvent> {
	public function new() {}

	public function dispatch():Void {
		dispatchObject(new SomeEvent()); // It`s OK

		inline dispatchObject(new SomeEvent()); // SomeEvent should be Dispatcher.TEvent

		inline dispatchObject(cast new SomeEvent()); // error: Dispatcher.TEvent should be SomeEvent

		var event:Dynamic = new SomeEvent();
		inline dispatchObject(event); // It`s OK
	}
}

Looks like a compiler bug. Please report here: https://github.com/HaxeFoundation/haxe/issues

1 Like

Ok thank you i did it

1 Like