Make sure changetype works

This commit is contained in:
dcodeIO
2018-01-02 05:02:05 +01:00
parent dc78fc8d20
commit 2b182b505e
7 changed files with 43 additions and 12 deletions

View File

@ -10,7 +10,7 @@ import {
Range
} from "./tokenizer";
import{
import {
CharCode
} from "./util/charcode";

View File

@ -694,11 +694,11 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
if (!validateCall(compiler, typeArguments, 1, operands, 1, reportNode))
return module.createUnreachable();
arg0 = compiler.compileExpression(operands[0], Type.void, ConversionKind.NONE);
if ((compiler.currentType == usizeType && (<Type[]>typeArguments)[1].classType) || (compiler.currentType.classType && (<Type[]>typeArguments)[1] == usizeType)) {
compiler.currentType = (<Type[]>typeArguments)[1];
if ((compiler.currentType == usizeType && (<Type[]>typeArguments)[0].classType) || (compiler.currentType.classType && (<Type[]>typeArguments)[0] == usizeType)) {
compiler.currentType = (<Type[]>typeArguments)[0];
return arg0;
}
compiler.error(DiagnosticCode.Type_0_cannot_be_changed_to_type_1, reportNode.range, (<Type[]>typeArguments)[0].toString(), (<Type[]>typeArguments)[1].toString());
compiler.error(DiagnosticCode.Type_0_cannot_be_changed_to_type_1, reportNode.range, compiler.currentType.toString(), (<Type[]>typeArguments)[0].toString());
return module.createUnreachable();
case "assert": // assert(isTrue: bool) -> void

View File

@ -1506,7 +1506,17 @@ export class Parser extends DiagnosticEmitter {
return Node.createFloatLiteral(tn.readFloat(), tn.range(startPos, tn.pos));
// RegexpLiteralExpression
case Token.REGEXPLITERAL:
/*
case Token.SLASH:
var regexpLit = Node.createRegexpLiteral(tn.readRegexp(), tn.range(startPos, tn.pos));
if (!tn.skip(Token.SLASH)) {
this.error(DiagnosticCode._0_expected, tn.range(), "/");
return null;
}
// TODO: modifiers, may be move to tokenizer
return regexpLit;
*/
case Token.REGEXPLITERAL: // not yet supported
return Node.createRegexpLiteral(tn.readRegexp(), tn.range(startPos, tn.pos));
default: