Skip to content

Commit

Permalink
[J2KT] Extend casts readable with a cast to RAW and then to generic t…
Browse files Browse the repository at this point in the history
…ype.

PiperOrigin-RevId: 719257894
  • Loading branch information
Googler authored and copybara-github committed Jan 24, 2025
1 parent 1108a9a commit 59575e5
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public <S, V extends Enum<V>> void testCastToMethodTypeVariable() {
c = (V) o;
}

public Foo<String> testCastToRawToGeneric(Foo<Object> foo) {
return (Foo<String>) (Foo) foo;
}

/**
* This method tests that J2CL correctly sets the Generic to its bound inside a method since
* closure compiler cannot handle it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class CastGenerics extends j_l_Object {
c = (/**@type {Array<S>}*/ ($Arrays.$castTo(o, j_l_Object, 1)));
c = (/**@type {V}*/ ($Casts.$to(o, Enum)));
}
/** @nodts @return {Foo<?string>} */
m_testCastToRawToGeneric__cast_CastGenerics_Foo__cast_CastGenerics_Foo(/** Foo<*> */ foo) {
return /**@type {Foo<?string>}*/ (foo);
}
/** @nodts @template TT */
m_outerGenericMethod__void() {}
/** @nodts @template EE @return {EE} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ open class CastGenerics<T, E: Number?> {
c = o as V?
}

@ObjCName("testCastToRawToGeneric")
open fun testCastToRawToGeneric(
@ObjCName("withCastCastGenerics_Foo") foo: CastGenerics.Foo<Any?>?
): CastGenerics.Foo<String?>? {
return foo as CastGenerics.Foo<Any?>? as CastGenerics.Foo<String?>?
}

@ObjCName("outerGenericMethod")
open fun <TT: Enum<*>> outerGenericMethod() {
open class Nested<SS> internal constructor() {
Expand Down
Loading

0 comments on commit 59575e5

Please sign in to comment.