UnityNativeScripting icon indicating copy to clipboard operation
UnityNativeScripting copied to clipboard

Bindings generator does not handle multiple derived types

Open philipcass opened this issue 4 years ago • 3 comments

I've noticed when you have several classes based of the same abstract class the codegen can't handle it even thought the syntax looks like it should e.g.

		{
			"Name": "MyNamespace.AbstractShape",
			"BaseTypes": [
				{
					"BaseName": "MyNamespace.BaseSquare",
					"DerivedName": "MyNamespace.Square"
				},
				{
					"BaseName": "MyNamespace.BaseCircle",
					"DerivedName": "MyNamespace.Circle"
				}
			]
		}

Doesn't work

philipcass avatar Feb 21 '21 12:02 philipcass

@philipcass Can you please elaborate on what doesn't work?

jacksondunstan avatar Feb 22 '21 01:02 jacksondunstan

@jacksondunstan When generating c sharp delegates for each instance of the derived types the code-gen redeclares the common abstract methods multiple times e.g. if GetRadius was declared in AbstractShape it'd create this twice:

		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		public delegate double MyNamespaceAbstractShapeGetRadiusDelegateType(int thisHandle);
		public static MyNamespaceAbstractShapeRadiusDelegateType MyNamespaceAbstractShapeGetRadiusDelegateType;

philipcass avatar Feb 22 '21 08:02 philipcass

@philipcass Thanks for clarifying. It looks like that code should only be generated for the first derived type, not all of them. I'm not able to address the issue right away, but please do feel free to submit a PR with a fix.

jacksondunstan avatar Feb 27 '21 19:02 jacksondunstan