reflaxe.CPP icon indicating copy to clipboard operation
reflaxe.CPP copied to clipboard

Template type argument is omitted on @:to implicit function call

Open fourst4r opened this issue 2 years ago • 1 comments

Building this code

abstract Flexible(Int) {
    public function new()
        this = 1;

    @:to function toAny<T>():T
        return null;
}

function main() {
    var r:String = new Flexible();
    trace(r);
}

Will generate the following C++

std::string r = _Main::Flexible_Impl_::toAny(_Main::Flexible_Impl_::_new());

Which gives a compile error: no instance of function template "_Main::Flexible_Impl_::toAny" matches the argument list.

Putting the type explicitly in the call site fixes the error, like so:

std::string r = _Main::Flexible_Impl_::toAny<std::string>(_Main::Flexible_Impl_::_new());

fourst4r avatar Jun 22 '23 05:06 fourst4r

Also note that calling toAny() explicitly: new Flexible().toAny() will produce the correct C++.

fourst4r avatar Jun 22 '23 05:06 fourst4r