mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
implements StructType.isSubTypeOf(x) for Arrays and Lambdas
This commit is contained in:
parent
1f167d99b9
commit
6d4379b2e8
@ -1206,6 +1206,17 @@ public class TypeManager {
|
||||
String getInterfaceMethodName() {
|
||||
return interfaceMethodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isSubTypeOf( AnyType type ) {
|
||||
if( type == this || type == ValueType.externref || type == ValueType.anyref || type == ValueType.eqref ) {
|
||||
return true;
|
||||
}
|
||||
return type == interfaceType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,6 +167,19 @@ public class ArrayType extends StructType {
|
||||
*/
|
||||
@Override
|
||||
public boolean isSubTypeOf( AnyType type ) {
|
||||
return type == this || type == ValueType.externref;
|
||||
if( type == this || type == ValueType.externref ) {
|
||||
return true;
|
||||
}
|
||||
if( !(type instanceof StructType) ) {
|
||||
return false;
|
||||
}
|
||||
StructType structType = (StructType)type;
|
||||
switch( structType.getKind() ) {
|
||||
case normal:
|
||||
return "java/lang/Object".equals( structType.getName() );
|
||||
case array:
|
||||
return arrayType.isSubTypeOf( ((ArrayType)structType).arrayType );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,14 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.inetsoftware.jwebassembly.JWebAssembly;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager.LambdaType;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructTypeKind;
|
||||
|
||||
@ -99,4 +101,12 @@ public class StructTypeTest {
|
||||
assertFalse( typeObjArray.isSubTypeOf( typeIntArray ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSubTypeOf_Lambda() throws Throwable {
|
||||
StructType typeRunnable = manager.valueOf( "java/lang/Runnable" );
|
||||
LambdaType lambda = manager.lambdaType( "typeName", new ArrayList(), typeRunnable, new FunctionName( "", "", "" ), "run" );
|
||||
|
||||
assertTrue( lambda.isSubTypeOf( typeRunnable ) );
|
||||
assertFalse( typeRunnable.isSubTypeOf( lambda ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user