-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[J2KT] Add readable to cover another case of nullability inference pr…
…oblem, which we don't want to regress. PiperOrigin-RevId: 728639938
- Loading branch information
1 parent
82ee7a7
commit f597107
Showing
3 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
transpiler/javatests/com/google/j2cl/readable/java/j2kt/NullabilityInferenceProblem6.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2025 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package j2kt; | ||
|
||
import org.jspecify.annotations.NullMarked; | ||
import org.jspecify.annotations.Nullable; | ||
|
||
@NullMarked | ||
public class NullabilityInferenceProblem6 { | ||
interface Consumer<V extends @Nullable Object> { | ||
void accept(V v); | ||
} | ||
|
||
interface Container<V extends @Nullable Object> { | ||
void forEach(Consumer<V> consumer); | ||
|
||
void add(V v); | ||
} | ||
|
||
interface Foo {} | ||
|
||
interface FooConsumer<V extends @Nullable Foo> { | ||
void accept(V v); | ||
} | ||
|
||
interface FooContainer<V extends @Nullable Foo> { | ||
void forEach(Consumer<V> consumer); | ||
|
||
void add(V v); | ||
} | ||
|
||
static void testLambda(Container<?> from, Container<? super @Nullable Object> to) { | ||
// The type of "it" parameter is incorrectly inferred as capture of non-null Object in the AST. | ||
from.forEach(it -> to.add(it)); | ||
} | ||
|
||
static void testMethodReference(Container<?> from, Container<? super @Nullable Object> to) { | ||
// The type of "it" parameter is incorrectly inferred as capture of non-null Object in the AST. | ||
from.forEach(to::add); | ||
} | ||
|
||
static void testLambda(FooContainer<?> from, FooContainer<? super @Nullable Foo> to) { | ||
// The type of "it" parameter is correctly inferred as capture of nullable Foo in the AST. | ||
from.forEach(it -> to.add(it)); | ||
} | ||
|
||
static void testMethodReference(FooContainer<?> from, FooContainer<? super @Nullable Foo> to) { | ||
// The type of "it" parameter is correctly inferred as capture of nullable Foo in the AST. | ||
from.forEach(to::add); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../google/j2cl/readable/java/j2kt/output_kt/NullabilityInferenceProblem6+J2ObjCCompat.h.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Generated by J2KT from "j2kt/NullabilityInferenceProblem6.java" | ||
|
||
#import <Foundation/NSObjCRuntime.h> | ||
|
||
@class J2ktJ2ktNullabilityInferenceProblem6; | ||
@class J2ktJ2ktNullabilityInferenceProblem6Companion; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@compatibility_alias J2ktNullabilityInferenceProblem6 J2ktJ2ktNullabilityInferenceProblem6; | ||
|
||
@compatibility_alias J2ktNullabilityInferenceProblem6Companion J2ktJ2ktNullabilityInferenceProblem6Companion; | ||
|
||
NS_ASSUME_NONNULL_END |
114 changes: 114 additions & 0 deletions
114
...avatests/com/google/j2cl/readable/java/j2kt/output_kt/NullabilityInferenceProblem6.kt.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Generated from "j2kt/NullabilityInferenceProblem6.java" | ||
@file:OptIn(ExperimentalObjCName::class) | ||
@file:Suppress( | ||
"ALWAYS_NULL", | ||
"PARAMETER_NAME_CHANGED_ON_OVERRIDE", | ||
"SENSELESS_COMPARISON", | ||
"UNCHECKED_CAST", | ||
"UNNECESSARY_LATEINIT", | ||
"UNNECESSARY_NOT_NULL_ASSERTION", | ||
"UNREACHABLE_CODE", | ||
"UNUSED_ANONYMOUS_PARAMETER", | ||
"UNUSED_PARAMETER", | ||
"UNUSED_VARIABLE", | ||
"USELESS_CAST", | ||
"VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL", | ||
"VARIABLE_WITH_REDUNDANT_INITIALIZER", | ||
"REDUNDANT_ELSE_IN_WHEN") | ||
|
||
package j2kt | ||
|
||
import javaemul.lang.* | ||
import kotlin.Any | ||
import kotlin.OptIn | ||
import kotlin.Suppress | ||
import kotlin.experimental.ExperimentalObjCName | ||
import kotlin.jvm.JvmStatic | ||
import kotlin.native.ObjCName | ||
|
||
@ObjCName("J2ktJ2ktNullabilityInferenceProblem6", exact = true) | ||
open class NullabilityInferenceProblem6 { | ||
@ObjCName("J2ktJ2ktNullabilityInferenceProblem6Companion", exact = true) | ||
companion object { | ||
@JvmStatic | ||
internal fun testLambda_pp_j2kt(from: NullabilityInferenceProblem6.Container<*>, to: NullabilityInferenceProblem6.Container<in Any?>) { | ||
(from as NullabilityInferenceProblem6.Container<Any?>).forEach( | ||
NullabilityInferenceProblem6.Consumer/* <capture#1-of out Any> */ { it /* capture#1-of out Any */ -> | ||
to.add(it) | ||
}, | ||
) | ||
} | ||
|
||
@JvmStatic | ||
internal fun testMethodReference_pp_j2kt(from: NullabilityInferenceProblem6.Container<*>, to: NullabilityInferenceProblem6.Container<in Any?>) { | ||
(from as NullabilityInferenceProblem6.Container<Any?>).forEach( | ||
NullabilityInferenceProblem6.Consumer/* <capture#2-of out Any> */ { arg0 /* capture#2-of out Any */ -> | ||
to.add(arg0) | ||
}, | ||
) | ||
} | ||
|
||
@JvmStatic | ||
internal fun testLambda_pp_j2kt(from: NullabilityInferenceProblem6.FooContainer<*>, to: NullabilityInferenceProblem6.FooContainer<in NullabilityInferenceProblem6.Foo?>) { | ||
(from as NullabilityInferenceProblem6.FooContainer<NullabilityInferenceProblem6.Foo?>).forEach( | ||
NullabilityInferenceProblem6.Consumer/* <capture#3-of out NullabilityInferenceProblem6.Foo?> */ { it /* capture#3-of out NullabilityInferenceProblem6.Foo? */ -> | ||
to.add(it) | ||
}, | ||
) | ||
} | ||
|
||
@JvmStatic | ||
internal fun testMethodReference_pp_j2kt(from: NullabilityInferenceProblem6.FooContainer<*>, to: NullabilityInferenceProblem6.FooContainer<in NullabilityInferenceProblem6.Foo?>) { | ||
(from as NullabilityInferenceProblem6.FooContainer<NullabilityInferenceProblem6.Foo?>).forEach( | ||
NullabilityInferenceProblem6.Consumer/* <capture#4-of out NullabilityInferenceProblem6.Foo?> */ { arg0 /* capture#4-of out NullabilityInferenceProblem6.Foo? */ -> | ||
to.add(arg0) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
@ObjCName("J2ktJ2ktNullabilityInferenceProblem6_Consumer", exact = true) | ||
fun interface Consumer<V> { | ||
@ObjCName("accept") | ||
fun accept( | ||
@ObjCName("withId") v: V | ||
) | ||
} | ||
|
||
@ObjCName("J2ktJ2ktNullabilityInferenceProblem6_Container", exact = true) | ||
interface Container<V> { | ||
@ObjCName("forEach") | ||
fun forEach( | ||
@ObjCName("withJ2ktNullabilityInferenceProblem6_Consumer") consumer: NullabilityInferenceProblem6.Consumer<V> | ||
) | ||
|
||
@ObjCName("add") | ||
fun add( | ||
@ObjCName("withId") v: V | ||
) | ||
} | ||
|
||
@ObjCName("J2ktJ2ktNullabilityInferenceProblem6_Foo", exact = true) | ||
interface Foo | ||
|
||
@ObjCName("J2ktJ2ktNullabilityInferenceProblem6_FooConsumer", exact = true) | ||
fun interface FooConsumer<V: NullabilityInferenceProblem6.Foo?> { | ||
@ObjCName("accept") | ||
fun accept( | ||
@ObjCName("withJ2ktNullabilityInferenceProblem6_Foo") v: V | ||
) | ||
} | ||
|
||
@ObjCName("J2ktJ2ktNullabilityInferenceProblem6_FooContainer", exact = true) | ||
interface FooContainer<V: NullabilityInferenceProblem6.Foo?> { | ||
@ObjCName("forEach") | ||
fun forEach( | ||
@ObjCName("withJ2ktNullabilityInferenceProblem6_Consumer") consumer: NullabilityInferenceProblem6.Consumer<V> | ||
) | ||
|
||
@ObjCName("add") | ||
fun add( | ||
@ObjCName("withJ2ktNullabilityInferenceProblem6_Foo") v: V | ||
) | ||
} | ||
} |