-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: additional casts at use place to help type inference (#1002)
- Loading branch information
Showing
9 changed files
with
227 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
35 changes: 35 additions & 0 deletions
35
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver16.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,35 @@ | ||
package jadx.tests.integration.types; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.SmaliTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
/** | ||
* Issue 1002 | ||
* Insertion of additional cast (at use place) needed for successful type inference | ||
*/ | ||
public class TestTypeResolver16 extends SmaliTest { | ||
// @formatter:off | ||
/* | ||
public final <T, K> List<T> test(List<? extends T> list, Set<? extends T> set, Function<? super T, ? extends K> function) { | ||
checkParameterIsNotNull(function, "distinctBy"); | ||
if (set != null) { | ||
List<? extends T> union = list != null ? union(list, set, function) : null; | ||
if (union != null) { | ||
list = union; | ||
} | ||
} | ||
return list != null ? (List<T>) list : emptyList(); | ||
} | ||
*/ | ||
// @formatter:on | ||
|
||
@Test | ||
public void test() { | ||
assertThat(getClassNodeFromSmali()) | ||
.code() | ||
.containsOne("(List<T>) list"); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
jadx-core/src/test/smali/types/TestTypeResolver16.smali
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,111 @@ | ||
.class public Ltypes/TestTypeResolver16; | ||
.super Ljava/lang/Object; | ||
|
||
.method public final test(Ljava/util/List;Ljava/util/Set;Ljava/util/function/Function;)Ljava/util/List; | ||
.locals 1 | ||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"<T:", | ||
"Ljava/lang/Object;", | ||
"K:", | ||
"Ljava/lang/Object;", | ||
">(", | ||
"Ljava/util/List<", | ||
"+TT;>;", | ||
"Ljava/util/Set<", | ||
"+TT;>;", | ||
"Ljava/util/function/Function<", | ||
"-TT;+TK;>;)", | ||
"Ljava/util/List<", | ||
"TT;>;" | ||
} | ||
.end annotation | ||
|
||
const-string v0, "distinctBy" | ||
|
||
invoke-static {p3, v0}, Ltypes/TestTypeResolver16;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V | ||
|
||
if-eqz p2, :cond_1 | ||
|
||
if-eqz p1, :cond_0 | ||
|
||
.line 85 | ||
move-object v0, p1 | ||
|
||
check-cast v0, Ljava/util/Collection; | ||
|
||
check-cast p2, Ljava/lang/Iterable; | ||
|
||
invoke-static {v0, p2, p3}, Ltypes/TestTypeResolver16;->union(Ljava/util/Collection;Ljava/lang/Iterable;Ljava/util/function/Function;)Ljava/util/List; | ||
|
||
move-result-object p2 | ||
|
||
goto :goto_0 | ||
|
||
:cond_0 | ||
const/4 p2, 0x0 | ||
|
||
:goto_0 | ||
if-eqz p2, :cond_1 | ||
|
||
move-object p1, p2 | ||
|
||
:cond_1 | ||
if-eqz p1, :cond_2 | ||
|
||
goto :goto_1 | ||
|
||
:cond_2 | ||
invoke-static {}, Ltypes/TestTypeResolver16;->emptyList()Ljava/util/List; | ||
|
||
move-result-object p1 | ||
|
||
:goto_1 | ||
return-object p1 | ||
.end method | ||
|
||
|
||
.method public static final union(Ljava/util/Collection;Ljava/lang/Iterable;Ljava/util/function/Function;)Ljava/util/List; | ||
.locals 4 | ||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"<T:", | ||
"Ljava/lang/Object;", | ||
"K:", | ||
"Ljava/lang/Object;", | ||
">(", | ||
"Ljava/util/Collection<", | ||
"+TT;>;", | ||
"Ljava/lang/Iterable<", | ||
"+TT;>;", | ||
"Ljava/util/function/Function<", | ||
"-TT;+TK;>;)", | ||
"Ljava/util/List<", | ||
"TT;>;" | ||
} | ||
.end annotation | ||
|
||
const/4 v0, 0x0 | ||
return-object v0 | ||
.end method | ||
|
||
.method public static checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V | ||
.locals 0 | ||
return-void | ||
.end method | ||
|
||
.method public static final emptyList()Ljava/util/List; | ||
.locals 1 | ||
.annotation system Ldalvik/annotation/Signature; | ||
value = { | ||
"<T:", | ||
"Ljava/lang/Object;", | ||
">()", | ||
"Ljava/util/List<", | ||
"TT;>;" | ||
} | ||
.end annotation | ||
|
||
const/4 v0, 0x0 | ||
return-object v0 | ||
.end method |