Add a way to ensure that lazy globals are resolved, fixes #355

This only affects static fields that currently must have a type annotation, while it wouldn't work if there wasn't an annotated type, like on normal globals, which aren't compiled lazily, though. Must be revisted if requirements on type annotations on fields ever become relaxed.
This commit is contained in:
dcodeIO
2018-12-01 13:31:37 +01:00
parent a661ff7d89
commit 0e33806cf6
4 changed files with 39 additions and 21 deletions

View File

@@ -696,7 +696,7 @@ export class Compiler extends DiagnosticEmitter {
var declaration = global.declaration;
var initExpr: ExpressionRef = 0;
if (global.type == Type.void) { // type is void if not yet resolved or not annotated
if (!global.is(CommonFlags.RESOLVED)) {
if (declaration) {
// resolve now if annotated
@@ -711,6 +711,7 @@ export class Compiler extends DiagnosticEmitter {
return false;
}
global.type = resolvedType;
global.set(CommonFlags.RESOLVED);
// infer from initializer if not annotated
} else if (declaration.initializer) { // infer type using void/NONE for literal inference
@@ -727,6 +728,7 @@ export class Compiler extends DiagnosticEmitter {
return false;
}
global.type = this.currentType;
global.set(CommonFlags.RESOLVED);
// must either be annotated or have an initializer
} else {
@@ -737,7 +739,7 @@ export class Compiler extends DiagnosticEmitter {
return false;
}
} else {
assert(false); // must have a declaration if 'void' (and thus resolved later on)
assert(false); // must have a declaration if resolved lazily
}
}