mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Fix bug when boxing primitive value inside lambda to supertype (e.g. java.lang.Object) of corresponding wrapper type
This commit is contained in:
parent
631111bdb3
commit
d71aec7c40
|
@ -748,6 +748,9 @@ public class ValueEmitter {
|
|||
if (!pe.hierarchy.isSuperType(targetClass, boxClassName, false)) {
|
||||
throw new EmitException("Can't convert " + this.type + " to " + targetClass);
|
||||
}
|
||||
if (!result.type.equals(type)) {
|
||||
result.type = type;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.teavm.vm;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import java.io.Serializable;
|
||||
import java.util.function.IntPredicate;
|
||||
import java.util.function.Supplier;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -41,6 +42,23 @@ public class LambdaTest {
|
|||
assertTrue("Supplier is expected to implement Serializable", supplier instanceof Serializable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boxParameterToSupertype() {
|
||||
assertEquals(".*.*.*.*.*", acceptIntPredicate(this::oddPredicate));
|
||||
}
|
||||
|
||||
private String acceptIntPredicate(IntPredicate p) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
sb.append(p.test(i) ? '*' : '.');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private boolean oddPredicate(Object o) {
|
||||
return o instanceof Integer && ((Integer) o) % 2 != 0;
|
||||
}
|
||||
|
||||
interface A {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user