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

Mono glue generates invalid code when casting negative number #73004

Closed
Atlinx opened this issue Feb 9, 2023 · 0 comments · Fixed by #77018
Closed

Mono glue generates invalid code when casting negative number #73004

Atlinx opened this issue Feb 9, 2023 · 0 comments · Fixed by #77018

Comments

@Atlinx
Copy link
Contributor

Atlinx commented Feb 9, 2023

Godot version

3.5.1, though it may also affect later versions

System information

Windows 11

Issue description

I'm building snopek games' sg_physics_2d module with godot 3.5, and this bit of C++ code

	// From sg_physics_2d_server.h
	RID collision_object_create(CollisionObjectType p_object_type, BodyType p_body_type = BODY_UNKNOWN);
	
	// From sg_physics_2d_server.cpp
	ClassDB::bind_method(D_METHOD("collision_object_create", "object_type", "body_type"), &SGPhysics2DServer::collision_object_create, DEFVAL(BODY_UNKNOWN));

gets converted into

        /// <summary>
        /// <para>Creates a collision object.</para>
        /// </summary>
        [GodotMethod("collision_object_create")]
        public static RID CollisionObjectCreate(SGPhysics2DServer.CollisionObjectType objectType, SGPhysics2DServer.BodyType bodyType = (SGPhysics2DServer.BodyType)-1)
        {
            return new RID(NativeCalls.godot_icall_2_881(method_bind_12, ptr, (int)objectType, (int)bodyType));
        }

Note that BODY_UNKNOWN is an enum value that evaluates to -1. Notice how there are no parentheses around the -1 in C# code, leading to a compiler error. Instead of (SGPhysics2DServer.BodyType)-1, it should be (SGPhysics2DServer.BodyType)(-1)

Steps to reproduce

N/A

Minimal reproduction project

See snopek games' sg-physics-2d repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants