1
0
mirror of https://github.com/fluencelabs/assemblyscript synced 2025-07-29 21:22:11 +00:00

Warn on constant locals not being actual constants; Simplify changetype

This commit is contained in:
dcodeIO
2017-12-28 17:16:37 +01:00
parent 2f12c7fa50
commit 4207f6460d
14 changed files with 90 additions and 74 deletions

@@ -689,11 +689,11 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
// other
case "changetype": // changetype<T1,T2>(value: T1) -> T2
if (!validateCall(compiler, typeArguments, 2, operands, 1, reportNode))
case "changetype": // changetype<T>(value: *) -> T
if (!validateCall(compiler, typeArguments, 1, operands, 1, reportNode))
return module.createUnreachable();
if ((typeArguments[0] == usizeType && typeArguments[1].classType) || (typeArguments[0].classType && typeArguments[1] == usizeType)) {
arg0 = compiler.compileExpression(operands[0], typeArguments[0]);
arg0 = compiler.compileExpression(operands[0], Type.void, ConversionKind.NONE);
if ((compiler.currentType == usizeType && typeArguments[1].classType) || (compiler.currentType.classType && typeArguments[1] == usizeType)) {
compiler.currentType = typeArguments[1];
return arg0;
}