Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Feb 22, 2022

No description provided.

@jpobst jpobst closed this Feb 22, 2022
@jpobst jpobst deleted the nrt branch February 22, 2022 16:07
jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Mar 3, 2022
Fixes: #955

Context: dotnet/android-libraries#488

Primitive types are not nullable in Java, thus we do not default them
to nullable when using nullable reference types in `generator`.
However, when we added Kotlin's unsigned primitive types we did not
special case them to not-nullable like the existing primitive types.

This causes compilation errors when trying to bind Kotlin stdlib with
`$(Nullable)`=enable:

	// Metadata.xml XPath method reference: path="/api/package[@name='kotlin.random']/class[@name='URandomKt']/method[@name='nextUInt-qCasIEU' and count(parameter)=2 and parameter[1][@type='kotlin.random.Random'] and parameter[2][@type='uint']]"
	[Register ("nextUInt-qCasIEU", "(Lkotlin/random/Random;I)I", "")]
	public static unsafe uint? NextUInt (global::Kotlin.Random.Random obj, uint? until)
	{
	    const string __id = "nextUInt-qCasIEU.(Lkotlin/random/Random;I)I";
	    try {
	        JniArgumentValue* __args = stackalloc JniArgumentValue [2];
	        __args [0] = new JniArgumentValue ((obj == null) ? IntPtr.Zero : ((global::Java.Lang.Object) obj).Handle);
	        __args [1] = new JniArgumentValue (until); // Error CS1503 Argument 1: cannot convert from 'uint?' to 'bool'
	        …

Error CS1503 is emitted when trying to invoke the non-existent
`JniArgumentValue(uint?)` constructor.

Add Kotlin unsigned types to
`CodeGenerationOptions.GetNullable(string)` so that unsigned types
are treated the same was as signed types.  This cause `generator` to
instead emit:

	// Metadata.xml XPath method reference: path="/api/package[@name='kotlin.random']/class[@name='URandomKt']/method[@name='nextUInt-qCasIEU' and count(parameter)=2 and parameter[1][@type='kotlin.random.Random'] and parameter[2][@type='uint']]"
	[Register ("nextUInt-qCasIEU", "(Lkotlin/random/Random;I)I", "")]
	public static unsafe uint NextUInt (global::Kotlin.Random.Random obj, uint until)
	{
	    const string __id = "nextUInt-qCasIEU.(Lkotlin/random/Random;I)I";
	    try {
	        JniArgumentValue* __args = stackalloc JniArgumentValue [2];
	        __args [0] = new JniArgumentValue ((obj == null) ? IntPtr.Zero : ((global::Java.Lang.Object) obj).Handle);
	        __args [1] = new JniArgumentValue (until);
	        …

Note the use of `uint` and not `uint?`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants