Skip to content

Commit 9a66208

Browse files
authored
Rework logical and/or type rules on contextual bool (#1264)
1 parent c397abb commit 9a66208

File tree

5 files changed

+2894
-11
lines changed

5 files changed

+2894
-11
lines changed

src/compiler.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5541,11 +5541,11 @@ export class Compiler extends DiagnosticEmitter {
55415541
let rightFlow = flow.fork();
55425542
this.currentFlow = rightFlow;
55435543
rightFlow.inheritNonnullIfTrue(leftExpr);
5544-
rightExpr = this.compileExpression(right, leftType, inheritedConstraints | Constraints.CONV_IMPLICIT);
5545-
rightType = leftType;
55465544

55475545
// simplify if only interested in true or false
55485546
if (contextualType == Type.bool || contextualType == Type.void) {
5547+
rightExpr = this.compileExpression(right, leftType, inheritedConstraints);
5548+
rightType = this.currentType;
55495549
rightExpr = this.performAutoreleasesWithValue(rightFlow, rightExpr, rightType);
55505550
rightFlow.freeScopedLocals();
55515551
this.currentFlow = flow;
@@ -5557,6 +5557,8 @@ export class Compiler extends DiagnosticEmitter {
55575557
this.currentType = Type.bool;
55585558

55595559
} else {
5560+
rightExpr = this.compileExpression(right, leftType, inheritedConstraints | Constraints.CONV_IMPLICIT);
5561+
rightType = this.currentType;
55605562

55615563
// references must properly retain and release, with the same outcome independent of the branch taken
55625564
if (leftType.isManaged) {
@@ -5643,11 +5645,11 @@ export class Compiler extends DiagnosticEmitter {
56435645
let rightFlow = flow.fork();
56445646
this.currentFlow = rightFlow;
56455647
rightFlow.inheritNonnullIfFalse(leftExpr);
5646-
rightExpr = this.compileExpression(right, leftType, inheritedConstraints | Constraints.CONV_IMPLICIT);
5647-
rightType = leftType;
56485648

56495649
// simplify if only interested in true or false
56505650
if (contextualType == Type.bool || contextualType == Type.void) {
5651+
rightExpr = this.compileExpression(right, leftType, inheritedConstraints);
5652+
rightType = this.currentType;
56515653
rightExpr = this.performAutoreleasesWithValue(rightFlow, rightExpr, leftType);
56525654
rightFlow.freeScopedLocals();
56535655
this.currentFlow = flow;
@@ -5659,6 +5661,8 @@ export class Compiler extends DiagnosticEmitter {
56595661
this.currentType = Type.bool;
56605662

56615663
} else {
5664+
rightExpr = this.compileExpression(right, leftType, inheritedConstraints | Constraints.CONV_IMPLICIT);
5665+
rightType = this.currentType;
56625666

56635667
// references must properly retain and release, with the same outcome independent of the branch taken
56645668
if (leftType.isManaged) {

tests/compiler/logical.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"asc_flags": [
3-
"--runtime none"
3+
"--runtime half",
4+
"--use ASC_RTRACE=1"
45
]
56
}

0 commit comments

Comments
 (0)