Skip to content

Rework constructor handling #446

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

Merged
merged 9 commits into from
Feb 2, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
skip final alloc in any terminating scenario
  • Loading branch information
dcodeIO committed Feb 2, 2019
commit 0d476f8fa187fee0e140dad848dc39c711b90eae
5 changes: 3 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,7 @@ export class Compiler extends DiagnosticEmitter {
assert(instance.is(CommonFlags.INSTANCE));
let classInstance = assert(instance.parent); assert(classInstance.kind == ElementKind.CLASS);

// implicitly return `this` if the constructor doesn't always return on its own
if (!flow.is(FlowFlags.RETURNS)) {
if (!flow.isAny(FlowFlags.ANY_TERMINATING)) {

// if `this` wasn't accessed before, allocate if necessary and initialize `this`
if (!flow.is(FlowFlags.ALLOCATES)) {
Expand All @@ -1133,6 +1132,8 @@ export class Compiler extends DiagnosticEmitter {
);
this.makeFieldInitialization(<Class>classInstance, stmts);
}

// implicitly return `this`
stmts.push(
module.createGetLocal(0, nativeSizeType)
);
Expand Down