Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 22 additions & 18 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5703,10 +5703,12 @@ export class Compiler extends DiagnosticEmitter {
assert(targetType != Type.void);
let valueExpr = this.compileExpression(valueExpression, targetType);
let valueType = this.currentType;
if (targetType.isNullableReference && this.currentFlow.isNonnull(valueExpr, valueType)) targetType = targetType.nonNullableType;
valueExpr = this.convertExpression(valueExpr, valueType, targetType, false, valueExpression);
return this.makeAssignment(
target,
this.convertExpression(valueExpr, valueType, targetType, false, valueExpression),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was better before, but this is okay.

valueType,
valueExpr,
targetType,
valueExpression,
thisExpression,
elementExpression,
Expand Down Expand Up @@ -5799,6 +5801,7 @@ export class Compiler extends DiagnosticEmitter {
return module.unreachable();
}
assert(setterInstance.signature.parameterTypes.length == 1);
assert(setterInstance.signature.returnType == Type.void);
if (propertyInstance.is(CommonFlags.Instance)) {
let thisType = assert(setterInstance.signature.thisType);
let thisExpr = this.compileExpression(
Expand All @@ -5807,28 +5810,29 @@ export class Compiler extends DiagnosticEmitter {
Constraints.ConvImplicit | Constraints.IsThis
);
if (!tee) return this.makeCallDirect(setterInstance, [ thisExpr, valueExpr ], valueExpression);
let getterInstance = assert((<Property>target).getterInstance);
assert(getterInstance.signature.thisType == thisType);
let returnType = getterInstance.signature.returnType;
let returnTypeRef = returnType.toRef();
let tempThis = flow.getTempLocal(thisType);
let tempLocal = flow.getTempLocal(valueType);
let valueTypeRef = valueType.toRef();
let ret = module.block(null, [
this.makeCallDirect(setterInstance, [
module.local_tee(tempThis.index, thisExpr, /* isManaged=*/false, thisType.toRef()), // thisType is managed but here it must be alive
valueExpr
thisExpr,
module.local_tee(tempLocal.index, valueExpr, valueType.isManaged, valueTypeRef)
], valueExpression),
this.makeCallDirect(getterInstance, [
module.local_get(tempThis.index, thisType.toRef())
], valueExpression)
], returnTypeRef);
module.local_get(tempLocal.index, valueTypeRef),
], valueTypeRef);
this.currentType = valueType;
return ret;
} else {
if (!tee) return this.makeCallDirect(setterInstance, [ valueExpr ], valueExpression);
let getterInstance = assert((<Property>target).getterInstance);
return module.block(null, [
this.makeCallDirect(setterInstance, [ valueExpr ], valueExpression),
this.makeCallDirect(getterInstance, null, valueExpression)
], getterInstance.signature.returnType.toRef());
let tempLocal = flow.getTempLocal(valueType);
let valueTypeRef = valueType.toRef();
let ret = module.block(null, [
this.makeCallDirect(setterInstance, [
module.local_tee(tempLocal.index, valueExpr, valueType.isManaged, valueTypeRef),
], valueExpression),
module.local_get(tempLocal.index, valueTypeRef),
], valueTypeRef);
this.currentType = valueType;
return ret;
}
}
case ElementKind.IndexSignature: {
Expand Down
Loading