Skip to content

Invalid parameter name when writing explicit interface property implementations #565

Closed
@jpobst

Description

@jpobst

We generate this:

// This method is explicitly implemented as a member of an instantiated Google.Android.Material.DatePicker.IDateSelector
global::Java.Lang.Object global::Google.Android.Material.DatePicker.IDateSelector.Selection {
	// Metadata.xml XPath method reference: path="/api/package[@name='com.google.android.material.datepicker']/interface[@name='DateSelector']/method[@name='getSelection' and count(parameter)=0]"
	[Register ("getSelection", "()Ljava/lang/Object;", "GetGetSelectionHandler:Google.Android.Material.DatePicker.IDateSelectorInvoker, Xamarin.Google.Android.Material")] get {
		return Selection;
	}
	// Metadata.xml XPath method reference: path="/api/package[@name='com.google.android.material.datepicker']/interface[@name='DateSelector']/method[@name='setSelection' and count(parameter)=1 and parameter[1][@type='S']]"
	[Register ("setSelection", "(Ljava/lang/Object;)V", "GetSetSelection_Ljava_lang_Object_Handler:Google.Android.Material.DatePicker.IDateSelectorInvoker, Xamarin.Google.Android.Material")] set {
		Selection = global::Java.Interop.JavaObjectExtensions.JavaCast<global::Java.Lang.Long>(p0);
	}
}

which results in this error:

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0103	The name 'p0' does not exist in the current context	com.google.android.material.material	D:\X\AndroidX-material\generated\com.google.android.material.material\obj\Debug\monoandroid90\generated\src\Google.Android.Material.DatePicker.SingleDateSelector.cs	397	Active

We need to temporarily modify the parameter name here:
https://github.com/xamarin/java.interop/blob/master/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs#L1608

writer.WriteLine ("{0}\t\t{1} = {2};", indent, property.Name, property.Setter.Parameters.GetGenericCall (opt, mappings));

Like we do here:
https://github.com/xamarin/java.interop/blob/master/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs#L1508

string pname = property.Setter.Parameters [0].Name;
property.Setter.Parameters [0].Name = "value";
WriteMethodBody (property.Setter, indent + "\t\t", gen);
property.Setter.Parameters [0].Name = pname;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions