Skip to content

Commit 0710219

Browse files
authored
Fix lost contextual types in instanceof (#1107)
1 parent 1ec68fe commit 0710219

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/compiler.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ export class Compiler extends DiagnosticEmitter {
26722672
type = resolver.resolveType( // reports
26732673
declaration.type,
26742674
flow.actualFunction,
2675-
flow.contextualTypeArguments
2675+
makeMap(flow.contextualTypeArguments)
26762676
);
26772677
if (!type) continue;
26782678
if (declaration.initializer) {
@@ -3464,7 +3464,7 @@ export class Compiler extends DiagnosticEmitter {
34643464
let toType = this.resolver.resolveType( // reports
34653465
assert(expression.toType),
34663466
flow.actualFunction,
3467-
flow.contextualTypeArguments
3467+
makeMap(flow.contextualTypeArguments)
34683468
);
34693469
if (!toType) return this.module.unreachable();
34703470
return this.compileExpression(expression.expression, toType, inheritedConstraints | Constraints.CONV_EXPLICIT);
@@ -7671,9 +7671,14 @@ export class Compiler extends DiagnosticEmitter {
76717671
// time of implementation, this seemed more useful because dynamic rhs expressions are not
76727672
// possible in AS anyway. also note that the code generated below must preserve side-effects of
76737673
// the LHS expression even when the result is a constant, i.e. return a block dropping `expr`.
7674+
var flow = this.currentFlow;
76747675
var expr = this.compileExpression(expression.expression, this.options.usizeType);
76757676
var actualType = this.currentType;
7676-
var expectedType = this.resolver.resolveType(expression.isType, this.currentFlow.actualFunction);
7677+
var expectedType = this.resolver.resolveType(
7678+
expression.isType,
7679+
flow.actualFunction,
7680+
makeMap(flow.contextualTypeArguments)
7681+
);
76777682
this.currentType = Type.bool;
76787683
if (!expectedType) return module.unreachable();
76797684

@@ -7714,7 +7719,6 @@ export class Compiler extends DiagnosticEmitter {
77147719
if (expectedType.isAssignableTo(actualType)) {
77157720
let program = this.program;
77167721
if (!(actualType.isUnmanaged || expectedType.isUnmanaged)) {
7717-
let flow = this.currentFlow;
77187722
let temp = flow.getTempLocal(actualType);
77197723
let instanceofInstance = assert(program.instanceofInstance);
77207724
this.compileFunction(instanceofInstance);
@@ -7764,7 +7768,6 @@ export class Compiler extends DiagnosticEmitter {
77647768
// FIXME: the temp local and the if can be removed here once flows
77657769
// perform null checking, which would error earlier when checking
77667770
// uninitialized (thus zero) `var a: A` to be an instance of something.
7767-
let flow = this.currentFlow;
77687771
let temp = flow.getTempLocal(actualType);
77697772
let instanceofInstance = assert(program.instanceofInstance);
77707773
this.compileFunction(instanceofInstance);

0 commit comments

Comments
 (0)