Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double throw generated in cpp Reflect.callMethod #11175

Closed
Aidan63 opened this issue Apr 22, 2023 · 1 comment
Closed

Double throw generated in cpp Reflect.callMethod #11175

Aidan63 opened this issue Apr 22, 2023 · 1 comment
Assignees

Comments

@Aidan63
Copy link
Contributor

Aidan63 commented Apr 22, 2023

A few months ago I started updating hxcpp's internal throw functions to use the C++ [[noreturn]] annotation to avoid needing to have return null() peppered around to make C++ compilers happy, but I ran into an issue I forgot about until now.

The generated Reflect.callMethod C++ seems to contain doubled up throws in it.

 ::Dynamic Reflect_obj::callMethod( ::Dynamic o, ::Dynamic func,::cpp::VirtualArray args){
            	HX_STACKFRAME(&_hx_pos_998f5550039526d3_54_callMethod)
HXLINE(  55)		if ((::hx::IsNotNull( func ) && ::hx::IsEq( func->__GetType(),3 ))) {
HXLINE(  56)			if (::hx::IsNull( o )) {
HXLINE(  57)				HX_STACK_DO_THROW(HX_STACK_DO_THROW(HX_INVALID_OBJECT));
            			}
HXLINE(  58)			func = o->__Field(func,::hx::paccDynamic);
            		}
HXLINE(  60)		if (::hx::IsNull( func )) {
HXLINE(  61)			HX_STACK_DO_THROW(HX_STACK_DO_THROW(HX_NULL_FUNCTION_POINTER));
            		}
HXLINE(  62)		func->__SetThis(o);
HXLINE(  63)		return func->__Run(args);
            	}

Initially I thought this might be a bug with gencpp but I don't think it is, looking at the pretty dump of the code the double throws appears there as well.

@:keep @:directlyUsed @:used @:coreApi @:analyzer(ignore)
class Reflect {

	@:has_untyped
	public static function callMethod(o:Dynamic, func:haxe.Function, args:Array<Dynamic>) {
		if ((func != null && func.__GetType() == 3)) {
			if ((o == null)) throw throw cpp.ErrorConstants.HX_INVALID_OBJECT;
			func = o.__Field(func, __cpp__("::hx::paccDynamic"));
		};
		if ((func == null)) throw throw cpp.ErrorConstants.HX_NULL_FUNCTION_POINTER;
		func.__SetThis(o);
		return func.__Run(args);
	}
}

These double throws does not appear in the original Reflect.callMethod and I have not been able to re-create this outside of this function yet.

public static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic
	untyped {
		if (func != null && func.__GetType() == ObjectType.vtString) {
			if (o == null)
				throw cpp.ErrorConstants.invalidObject;
			func = o.__Field(func, untyped __cpp__("::hx::paccDynamic"));
		}
		if (func == null)
			throw cpp.ErrorConstants.nullFunctionPointer;
		untyped func.__SetThis(o);
		return untyped func.__Run(args);
	
	}
@Simn Simn self-assigned this Feb 6, 2024
@Simn
Copy link
Member

Simn commented Feb 6, 2024

This comes from the @:analyzer(ignore) on hxcpp's Reflect class, and can be easily reproduced:

@:analyzer(ignore)
function main() {
	throw "foo";
}

Dump:

	@:keep @:analyzer(ignore)
	public static function main() {
		throw throw "foo";
	}

Will check where this goes wrong.

@Simn Simn closed this as completed in dbc9952 Feb 6, 2024
kLabz pushed a commit that referenced this issue Feb 18, 2024
kLabz pushed a commit that referenced this issue Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants