Skip to content

[generator] Fix case not renaming property setter parameter to "value" #566

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

Merged
merged 1 commit into from
Feb 10, 2020

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Feb 7, 2020

Fixes: #565

In a case with generics, we were not renaming the property setter parameter to value which meant it was left as p0 which is not valid C#.

Before:

set {
  Selection = JavaCast<Long> (p0);
}

Now:

set {
  Selection = JavaCast<Long> (value);
}

@jpobst jpobst changed the title [generator] Fix case where we were not renaming property setter parameter to "value" [generator] Fix case not renaming property setter parameter to "value" Feb 7, 2020
@jpobst jpobst requested a review from jonpryor February 7, 2020 17:26
@jonpryor jonpryor merged commit bfc0273 into master Feb 10, 2020
@jonpryor jonpryor deleted the fix-prop-parameter-name branch February 10, 2020 21:50
jonpryor pushed a commit that referenced this pull request Feb 19, 2020
Fixes: #565

In a case with generics, we were not renaming the property setter
parameter to `value`, which meant it could be left as `p0`, which is
not valid C#:

	// 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);
	    }
	}

This would result in a C# error:

	error CS0103: The name 'p0' does not exist in the current context.

The fix is to temporarily override the property's setter's parameter
name to `value` so that we emit compilable C# code:

	set {
	    Selection = JavaObjectExtensions.JavaCast<Long>(value);
	}
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid parameter name when writing explicit interface property implementations
3 participants