Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce strict field initialization #1349

Merged
merged 10 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,15 +748,27 @@ export abstract class Node {
return false;
}

/** Checks if this is a call calling a method on super. */
get isCallOnSuper(): bool {
if (this.kind != NodeKind.CALL) return false;
var expression = changetype<CallExpression>(this).expression;
if (expression.kind != NodeKind.PROPERTYACCESS) return false;
var target = (<PropertyAccessExpression>expression).expression;
if (target.kind == NodeKind.SUPER) return true;
private isAccessOn(kind: NodeKind): bool {
let node = changetype<Node>(this);
if (node.kind == NodeKind.CALL) {
node = (<CallExpression>node).expression;
}
if (node.kind == NodeKind.PROPERTYACCESS) {
let target = (<PropertyAccessExpression>node).expression;
if (target.kind == kind) return true;
}
return false;
}

/** Checks if this node accesses a method or property on `this`. */
get isAccessOnThis(): bool {
return this.isAccessOn(NodeKind.THIS);
}

/** Checks if this node accesses a method or property on `super`. */
get isAccessOnSuper(): bool {
return this.isAccessOn(NodeKind.SUPER);
}
}

// types
Expand Down Expand Up @@ -1518,12 +1530,12 @@ export class Source extends Node {
/** Full source text. */
public text: string
) {
super(NodeKind.SOURCE, changetype<Range>(0)); // ¯\(ツ)/¯
this.range = new Range(this, 0, text.length);
super(NodeKind.SOURCE, new Range(0, text.length));
var internalPath = mangleInternalPath(normalizedPath);
this.internalPath = internalPath;
var pos = internalPath.lastIndexOf(PATH_DELIMITER);
this.simplePath = pos >= 0 ? internalPath.substring(pos + 1) : internalPath;
this.range.source = this;
}

/** Path used internally. */
Expand Down
4 changes: 3 additions & 1 deletion src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2894,7 +2894,9 @@ function builtin_instantiate(ctx: BuiltinContext): ExpressionRef {
return module.unreachable();
}
compiler.currentType = classInstance.type;
return compiler.compileInstantiate(classInstance, operands, Constraints.NONE, ctx.reportNode);
var ctor = compiler.ensureConstructor(classInstance, ctx.reportNode);
compiler.checkFieldInitialization(classInstance, ctx.reportNode);
return compiler.compileInstantiate(ctor, operands, Constraints.NONE, ctx.reportNode);
}
builtins.set(BuiltinNames.instantiate, builtin_instantiate);

Expand Down
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export enum CommonFlags {
/** Has a `set` modifier. */
SET = 1 << 12,
/** Has a definite assignment assertion `!` as in `x!: i32;`. */
DEFINITE_ASSIGNMENT = 1 << 13,
DEFINITELY_ASSIGNED = 1 << 13,

// Extended modifiers usually derived from basic modifiers

Expand Down
Loading