-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[J2KT] Reproduces problem with method argument type inference and gen…
…eric class literal. PiperOrigin-RevId: 700301392
- Loading branch information
1 parent
7ef2124
commit dadcb7e
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
transpiler/javatests/com/google/j2cl/readable/java/j2ktnotpassing/GenericClassLiteral.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,34 @@ | ||
/* | ||
* Copyright 2024 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 j2ktnotpassing; | ||
|
||
import org.jspecify.annotations.NullMarked; | ||
|
||
// TODO(b/381046077): Move to `j2kt` when fixed. | ||
@NullMarked | ||
public class GenericClassLiteral { | ||
public interface Generic<T> {} | ||
|
||
public interface Foo {} | ||
|
||
public void test(Generic<Foo> genericFoo) { | ||
// J2KT renders invalid method type parameter and inserts invalid cast: | ||
// {@code accept<Generic<Any>>(genericFoo as GenericFoo<Any>, Generic::class.javaObjectType)} | ||
accept(genericFoo, Generic.class); | ||
} | ||
|
||
public <T> void accept(T foo, Class<T> cls) {} | ||
} |
18 changes: 18 additions & 0 deletions
18
...google/j2cl/readable/java/j2ktnotpassing/output_kt/GenericClassLiteral+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,18 @@ | ||
// Generated by J2KT from "j2ktnotpassing/GenericClassLiteral.java" | ||
|
||
#import <Foundation/NSObjCRuntime.h> | ||
|
||
@class J2ktJ2ktnotpassingGenericClassLiteral; | ||
|
||
@protocol J2ktJ2ktnotpassingGenericClassLiteral_Foo; | ||
@protocol J2ktJ2ktnotpassingGenericClassLiteral_Generic; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@compatibility_alias J2ktnotpassingGenericClassLiteral J2ktJ2ktnotpassingGenericClassLiteral; | ||
|
||
#define J2ktnotpassingGenericClassLiteral_Generic J2ktJ2ktnotpassingGenericClassLiteral_Generic | ||
|
||
#define J2ktnotpassingGenericClassLiteral_Foo J2ktJ2ktnotpassingGenericClassLiteral_Foo | ||
|
||
NS_ASSUME_NONNULL_END |
50 changes: 50 additions & 0 deletions
50
...vatests/com/google/j2cl/readable/java/j2ktnotpassing/output_kt/GenericClassLiteral.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,50 @@ | ||
// Generated from "j2ktnotpassing/GenericClassLiteral.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 j2ktnotpassing | ||
|
||
import javaemul.lang.* | ||
import java.lang.Class | ||
import kotlin.Any | ||
import kotlin.OptIn | ||
import kotlin.Suppress | ||
import kotlin.experimental.ExperimentalObjCName | ||
import kotlin.jvm.javaObjectType | ||
import kotlin.native.ObjCName | ||
|
||
@ObjCName("J2ktJ2ktnotpassingGenericClassLiteral", exact = true) | ||
open class GenericClassLiteral { | ||
@ObjCName("test") | ||
open fun test( | ||
@ObjCName("withJ2ktnotpassingGenericClassLiteral_Generic") genericFoo: GenericClassLiteral.Generic<GenericClassLiteral.Foo> | ||
) { | ||
this.accept<GenericClassLiteral.Generic<Any>>(genericFoo as GenericClassLiteral.Generic<Any>, GenericClassLiteral.Generic::class.javaObjectType) | ||
} | ||
|
||
@ObjCName("accept") | ||
open fun <T: Any> accept( | ||
@ObjCName("withId") foo: T, | ||
@ObjCName("withIOSClass") cls: Class<T> | ||
) {} | ||
|
||
@ObjCName("J2ktJ2ktnotpassingGenericClassLiteral_Generic", exact = true) | ||
interface Generic<T: Any> {} | ||
|
||
@ObjCName("J2ktJ2ktnotpassingGenericClassLiteral_Foo", exact = true) | ||
interface Foo {} | ||
} |