Skip to content

Commit 2d64a8b

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents 30fdeb1 + 1d25051 commit 2d64a8b

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

src/compiler.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,9 +2592,6 @@ export class Compiler extends DiagnosticEmitter {
25922592
var flow = this.currentFlow;
25932593
var returnType = flow.returnType;
25942594

2595-
// Remember that this flow returns
2596-
flow.set(FlowFlags.RETURNS | FlowFlags.TERMINATES);
2597-
25982595
var valueExpression = statement.value;
25992596
if (valueExpression) {
26002597
if (returnType == Type.void) {
@@ -2633,6 +2630,9 @@ export class Compiler extends DiagnosticEmitter {
26332630
}
26342631
flow.freeScopedLocals();
26352632

2633+
// Remember that this flow returns
2634+
flow.set(FlowFlags.RETURNS | FlowFlags.TERMINATES);
2635+
26362636
// If the last statement anyway, make it the block's return value
26372637
if (isLastInBody && expr != 0 && returnType != Type.void) {
26382638
if (!stmts.length) return expr;
@@ -5711,7 +5711,7 @@ export class Compiler extends DiagnosticEmitter {
57115711
target,
57125712
expr, // TODO: delay release above if possible?
57135713
this.currentType,
5714-
left,
5714+
right,
57155715
resolver.currentThisExpression,
57165716
resolver.currentElementExpression,
57175717
contextualType != Type.void
@@ -5850,12 +5850,13 @@ export class Compiler extends DiagnosticEmitter {
58505850

58515851
// compile the value and do the assignment
58525852
assert(targetType != Type.void);
5853-
var valueExpr = this.compileExpression(valueExpression, targetType, Constraints.CONV_IMPLICIT | Constraints.WILL_RETAIN);
5853+
var valueExpr = this.compileExpression(valueExpression, targetType, Constraints.WILL_RETAIN);
5854+
var valueType = this.currentType;
58545855
return this.makeAssignment(
58555856
target,
5856-
valueExpr,
5857-
this.currentType,
5858-
expression,
5857+
this.convertExpression(valueExpr, valueType, targetType, false, false, valueExpression),
5858+
valueType,
5859+
valueExpression,
58595860
thisExpression,
58605861
elementExpression,
58615862
contextualType != Type.void

src/flow.ts

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -764,35 +764,48 @@ export class Flow {
764764

765765
this.flags = newFlags | (this.flags & FlowFlags.UNCHECKED_CONTEXT);
766766

767-
var leftLocalFlags = left.localFlags;
768-
var numLeftLocalFlags = leftLocalFlags.length;
769-
var rightLocalFlags = right.localFlags;
770-
var numRightLocalFlags = rightLocalFlags.length;
771-
var maxLocalFlags = max(numLeftLocalFlags, numRightLocalFlags);
772-
var combinedFlags = new Array<LocalFlags>(maxLocalFlags);
773-
for (let i = 0; i < maxLocalFlags; ++i) {
774-
let leftFlags = i < numLeftLocalFlags ? leftLocalFlags[i] : 0;
775-
let rightFlags = i < numRightLocalFlags ? rightLocalFlags[i] : 0;
776-
let newFlags = leftFlags & rightFlags & (
777-
LocalFlags.CONSTANT |
778-
LocalFlags.WRAPPED |
779-
LocalFlags.NONNULL |
780-
LocalFlags.INITIALIZED
781-
);
782-
if (leftFlags & LocalFlags.RETAINED) {
783-
if (rightFlags & LocalFlags.RETAINED) {
784-
newFlags |= LocalFlags.RETAINED;
785-
} else {
767+
var thisLocalFlags = this.localFlags;
768+
if (leftFlags & FlowFlags.TERMINATES) {
769+
if (!(rightFlags & FlowFlags.TERMINATES)) {
770+
let rightLocalFlags = right.localFlags;
771+
for (let i = 0, k = rightLocalFlags.length; i < k; ++i) {
772+
thisLocalFlags[i] = rightLocalFlags[i];
773+
}
774+
}
775+
} else if (rightFlags & FlowFlags.TERMINATES) {
776+
let leftLocalFlags = left.localFlags;
777+
for (let i = 0, k = leftLocalFlags.length; i < k; ++i) {
778+
thisLocalFlags[i] = leftLocalFlags[i];
779+
}
780+
} else {
781+
let leftLocalFlags = left.localFlags;
782+
let numLeftLocalFlags = leftLocalFlags.length;
783+
let rightLocalFlags = right.localFlags;
784+
let numRightLocalFlags = rightLocalFlags.length;
785+
let maxLocalFlags = max(numLeftLocalFlags, numRightLocalFlags);
786+
for (let i = 0; i < maxLocalFlags; ++i) {
787+
let leftFlags = i < numLeftLocalFlags ? leftLocalFlags[i] : 0;
788+
let rightFlags = i < numRightLocalFlags ? rightLocalFlags[i] : 0;
789+
let newFlags = leftFlags & rightFlags & (
790+
LocalFlags.CONSTANT |
791+
LocalFlags.WRAPPED |
792+
LocalFlags.NONNULL |
793+
LocalFlags.INITIALIZED
794+
);
795+
if (leftFlags & LocalFlags.RETAINED) {
796+
if (rightFlags & LocalFlags.RETAINED) {
797+
newFlags |= LocalFlags.RETAINED;
798+
} else {
799+
newFlags |= LocalFlags.CONDITIONALLY_RETAINED;
800+
}
801+
} else if (rightFlags & LocalFlags.RETAINED) {
786802
newFlags |= LocalFlags.CONDITIONALLY_RETAINED;
803+
} else {
804+
newFlags |= (leftFlags | rightFlags) & LocalFlags.CONDITIONALLY_RETAINED;
787805
}
788-
} else if (rightFlags & LocalFlags.RETAINED) {
789-
newFlags |= LocalFlags.CONDITIONALLY_RETAINED;
790-
} else {
791-
newFlags |= (leftFlags | rightFlags) & LocalFlags.CONDITIONALLY_RETAINED;
806+
thisLocalFlags[i] = newFlags;
792807
}
793-
combinedFlags[i] = newFlags;
794808
}
795-
this.localFlags = combinedFlags;
796809
}
797810

798811
/** Tests if the specified flows have differing local states. */

src/parser.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,6 @@ export class Parser extends DiagnosticEmitter {
12961296
if (!type) return null;
12971297
} else {
12981298
type = Node.createOmittedType(tn.range(tn.pos));
1299-
type = type!; // FIXME: WHY?
13001299
}
13011300
let initializer: Expression | null = null;
13021301
if (tn.skip(Token.EQUALS)) {
@@ -1423,7 +1422,6 @@ export class Parser extends DiagnosticEmitter {
14231422
returnType = Node.createOmittedType(
14241423
tn.range(tn.pos)
14251424
);
1426-
returnType = returnType!; // FIXME: WHY?
14271425
if (!isSetter) {
14281426
this.error(
14291427
DiagnosticCode.Type_expected,
@@ -1532,7 +1530,6 @@ export class Parser extends DiagnosticEmitter {
15321530
if (!returnType) return null;
15331531
} else {
15341532
returnType = Node.createOmittedType(tn.range(tn.pos));
1535-
returnType = returnType!; // FIXME: WHY?
15361533
}
15371534

15381535
if (arrowKind) {
@@ -2082,7 +2079,6 @@ export class Parser extends DiagnosticEmitter {
20822079
if (!returnType) return null;
20832080
} else {
20842081
returnType = Node.createOmittedType(tn.range(tn.pos));
2085-
returnType = returnType!; // FIXME: WHY?
20862082
if (!isSetter && name.kind != NodeKind.CONSTRUCTOR) {
20872083
this.error(
20882084
DiagnosticCode.Type_expected,
@@ -3543,7 +3539,6 @@ export class Parser extends DiagnosticEmitter {
35433539
return null;
35443540
}
35453541
inner = Node.createParenthesizedExpression(inner, tn.range(startPos, tn.pos));
3546-
inner = inner!; // FIXME: WHY?
35473542
return this.maybeParseCallExpression(tn, inner);
35483543
}
35493544
// ArrayLiteralExpression
@@ -3833,7 +3828,6 @@ export class Parser extends DiagnosticEmitter {
38333828
null,
38343829
tn.range(startPos, tn.pos)
38353830
);
3836-
expr = expr!; // FIXME: WHY?
38373831
expr = this.maybeParseCallExpression(tn, expr);
38383832
break;
38393833
}
@@ -3864,7 +3858,6 @@ export class Parser extends DiagnosticEmitter {
38643858
next,
38653859
tn.range(startPos, tn.pos)
38663860
);
3867-
expr = expr!; // FIXME: WHY?
38683861
expr = this.maybeParseCallExpression(tn, expr);
38693862
break;
38703863
}
@@ -3932,7 +3925,6 @@ export class Parser extends DiagnosticEmitter {
39323925
<IdentifierExpression>next,
39333926
tn.range(startPos, tn.pos)
39343927
);
3935-
expr = expr!; // FIXME: WHY?
39363928
} else {
39373929
let next = this.parseExpression(tn, nextPrecedence + 1);
39383930
if (!next) return null;

0 commit comments

Comments
 (0)