Skip to content

Commit

Permalink
[J2KT] Reproduces problem with method argument type inference and gen…
Browse files Browse the repository at this point in the history
…eric class literal.

PiperOrigin-RevId: 700301392
  • Loading branch information
Googler authored and copybara-github committed Nov 26, 2024
1 parent 7ef2124 commit dadcb7e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
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) {}
}
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
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 {}
}

0 comments on commit dadcb7e

Please sign in to comment.