1
0
mirror of https://github.com/fluencelabs/assemblyscript synced 2025-06-22 11:11:43 +00:00

Statically eliminate unnecessary branches in generic contexts

In order to use the new compile time type checks in generics, untaken branches must be skipped because these might be invalid.
This commit is contained in:
dcodeIO
2018-03-17 14:40:58 +01:00
parent 2ed9fac171
commit 83e96892f2
18 changed files with 818 additions and 1769 deletions

@ -1459,12 +1459,17 @@ export class Parser extends DiagnosticEmitter {
flags |= CommonFlags.STATIC;
staticStart = tn.tokenPos;
staticEnd = tn.pos;
} else if (tn.skip(Token.ABSTRACT)) {
flags |= (CommonFlags.ABSTRACT | CommonFlags.INSTANCE);
abstractStart = tn.tokenPos;
abstractEnd = tn.pos;
} else {
flags |= CommonFlags.INSTANCE;
if (tn.skip(Token.ABSTRACT)) {
flags |= (CommonFlags.ABSTRACT | CommonFlags.INSTANCE);
abstractStart = tn.tokenPos;
abstractEnd = tn.pos;
} else {
flags |= CommonFlags.INSTANCE;
}
if (parentFlags & CommonFlags.GENERIC) {
flags |= CommonFlags.GENERIC_CONTEXT;
}
}
var readonlyStart: i32 = 0;
@ -2737,12 +2742,12 @@ export class Parser extends DiagnosticEmitter {
// fall-through
}
// function expression
case Token.QUESTION: // optional parameter
case Token.COLON: { // type annotation
tn.reset(state);
return this.parseFunctionExpression(tn);
}
// can be both
case Token.QUESTION: // optional parameter or ternary
case Token.COMMA: {
break; // continue
}