Skip to content
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

fix: return the assigned value in assignments #2773

Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 20 additions & 17 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5703,10 +5703,11 @@ 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;
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,
targetType,
valueExpression,
thisExpression,
elementExpression,
Expand Down Expand Up @@ -5799,6 +5800,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 +5809,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