Skip to content

Compile error using managedType metadata and non-blittable types #1331

@jpobst

Description

@jpobst

Imagine you have bound a method that has a non-blittable (bool/char) parameter. With 57f7bc8, generator will now cast the parameters as sbyte/ushort:

// Metadata.xml XPath method reference: path="/api/package[@name='androidx.work.impl.constraints.controllers']/class[@name='BatteryChargingController']/method[@name='isConstrained' and count(parameter)=1 and parameter[1][@type='boolean']]"
[Register ("isConstrained", "(Z)Z", "")]
protected override unsafe bool IsConstrained (bool value)
{
	const string __id = "isConstrained.(Z)Z";
	try {
		JniArgumentValue* __args = stackalloc JniArgumentValue [1];
		__args [0] = new JniArgumentValue (value ? (sbyte) 1 : (sbyte) 0);
		var __rm = _members.InstanceMethods.InvokeAbstractBooleanMethod (__id, this, __args);
		return __rm;
	} finally {
		global::System.GC.KeepAlive (value);
	}
}

However, if you have used managedType metadata to change the parameter type, for example to Java.Lang.Object, the cast will still be added but will not compile:

<attr
	path="/api/package[@name='androidx.work.impl.constraints.controllers']/class[@name='BatteryChargingController']/method[@name='isConstrained' and count(parameter)=1]/parameter[1]" 
	name="managedType">
        Java.Lang.Object
</attr>
// Metadata.xml XPath method reference: path="/api/package[@name='androidx.work.impl.constraints.controllers']/class[@name='BatteryChargingController']/method[@name='isConstrained' and count(parameter)=1 and parameter[1][@type='boolean']]"
[Register ("isConstrained", "(Z)Z", "")]
protected override unsafe bool IsConstrained (global::Java.Lang.Object? value)
{
	const string __id = "isConstrained.(Z)Z";
	try {
		JniArgumentValue* __args = stackalloc JniArgumentValue [1];
		__args [0] = new JniArgumentValue (value ? (sbyte) 1 : (sbyte) 0);  // Generated
		var __rm = _members.InstanceMethods.InvokeAbstractBooleanMethod (__id, this, __args);
		return __rm;
	} finally {
		global::System.GC.KeepAlive (value);
	}
}
error CS0266: Cannot implicitly convert type 'Java.Lang.Object' to 'bool'. An explicit conversion exists (are you missing a cast?) 

Fixing this requires removing the method with <remove-node> and hand-binding the method with the needed cast.

__args [0] = new JniArgumentValue ((bool)value ? (sbyte) 1 : (sbyte) 0);

Metadata

Metadata

Assignees

No one assigned

    Labels

    generatorIssues binding a Java library (generator, class-parse, etc.)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions