Add error message for not supported class constants

This commit is contained in:
Volker Berlin 2020-02-23 17:51:32 +01:00
parent a57d3020f9
commit 762ecba363
2 changed files with 17 additions and 1 deletions

View File

@ -371,8 +371,11 @@ public abstract class WasmCodeBuilder {
FunctionName name = strings.getStringConstantFunction();
instructions.add( new WasmConstInstruction( id, ValueType.i32, javaCodePos, lineNumber ) );
addCallInstruction( name, javaCodePos, lineNumber );
} else {
} else if( value instanceof Number ) {
instructions.add( new WasmConstInstruction( (Number)value, javaCodePos, lineNumber ) );
} else {
//TODO There can be ConstantClass, MethodType and MethodHandle
throw new WasmException( "Class constants are not supported. : " + value, lineNumber );
}
}

View File

@ -151,4 +151,17 @@ public class RuntimeErrors {
return (Integer)obj;
}
}
@Test
public void classConatnt() throws IOException {
compileErrorTest( "Class constants are not supported.", ClassConstant.class );
}
static class ClassConstant {
@Export
static Object runnable() {
Class elemtentType = Integer.class;
return java.lang.reflect.Array.newInstance(elemtentType, 42);
}
}
}