···7373}
74747575export function update(cat) {
7676- let _record = cat;
7777- new Cat("Sid", _record.cuteness)
7878- let _record$1 = cat;
7979- new Cat(
8080- "Bartholemew Wonder Puss the Fourth !!!!!!!!!!!!!!!!",
8181- _record$1.cuteness,
8282- )
8383- let _record$2 = new_cat();
8484- new Cat("Molly", _record$2.cuteness)
7676+ new Cat("Sid", cat.cuteness)
7777+ new Cat("Bartholemew Wonder Puss the Fourth !!!!!!!!!!!!!!!!", cat.cuteness)
7878+ let _record = new_cat();
7979+ new Cat("Molly", _record.cuteness)
8580 let box = new Box(cat);
8686- let _record$3 = box.occupant;
8787- return new Cat(_record$3.name, box.occupant.cuteness + 1);
8181+ let _record$1 = box.occupant;
8282+ return new Cat(_record$1.name, box.occupant.cuteness + 1);
8883}
89849085export const felix = /* @__PURE__ */ new Cat("Felix", 12);
···11---
22source: compiler-core/src/javascript/tests/custom_types.rs
33+assertion_line: 605
34expression: "\npub type Thing {\n Thing(constructor: Nil)\n}\n\npub fn main() {\n let a = Thing(constructor: Nil)\n let b = Thing(..a, constructor: Nil)\n b.constructor\n}\n"
55+snapshot_kind: text
46---
57----- SOURCE CODE
68···2830export function main() {
2931 let a = new Thing(undefined);
3032 let _block;
3131- let _record = a;
3233 _block = new Thing(undefined);
3334 let b = _block;
3435 return b.constructor$;
···11---
22source: compiler-core/src/javascript/tests/custom_types.rs
33+assertion_line: 622
34expression: "\npub type Thing {\n Thing(then: Nil)\n}\n\npub fn main() {\n let a = Thing(then: Nil)\n let b = Thing(..a, then: Nil)\n b.then\n}\n"
55+snapshot_kind: text
46---
57----- SOURCE CODE
68···2830export function main() {
2931 let a = new Thing(undefined);
3032 let _block;
3131- let _record = a;
3233 _block = new Thing(undefined);
3334 let b = _block;
3435 return b.then$;
+30-25
compiler-core/src/type_/expression.rs
···30373037 let record_location = record.location();
30383038 let record_type = record.type_();
3039303930403040- // We create an Assignment for the old record expression and will use a Var expression
30413041- // to refer back to it while constructing the arguments.
30423042- let record_assignment = Assignment {
30433043- location: record_location,
30443044- pattern: Pattern::Variable {
30403040+ let (record_var, record_assignment) = if record.is_var() {
30413041+ (record, None)
30423042+ } else {
30433043+ // We create an Assignment for the old record expression and will use a Var expression
30443044+ // to refer back to it while constructing the arguments.
30453045+ let record_assignment = Assignment {
30453046 location: record_location,
30463046- name: RECORD_UPDATE_VARIABLE.into(),
30473047- type_: record_type.clone(),
30483048- origin: VariableOrigin::generated(),
30493049- },
30503050- annotation: None,
30513051- compiled_case: CompiledCase::failure(),
30523052- kind: AssignmentKind::Generated,
30533053- value: record,
30543054- };
30553055-30563056- let record_var = TypedExpr::Var {
30573057- location: record_location,
30583058- constructor: ValueConstructor {
30593059- publicity: Publicity::Private,
30603060- deprecation: Deprecation::NotDeprecated,
30613061- type_: record_type,
30623062- variant: ValueConstructorVariant::LocalVariable {
30473047+ pattern: Pattern::Variable {
30633048 location: record_location,
30493049+ name: RECORD_UPDATE_VARIABLE.into(),
30503050+ type_: record_type.clone(),
30643051 origin: VariableOrigin::generated(),
30653052 },
30663066- },
30673067- name: RECORD_UPDATE_VARIABLE.into(),
30533053+ annotation: None,
30543054+ compiled_case: CompiledCase::failure(),
30553055+ kind: AssignmentKind::Generated,
30563056+ value: record,
30573057+ };
30583058+30593059+ let record_var = TypedExpr::Var {
30603060+ location: record_location,
30613061+ constructor: ValueConstructor {
30623062+ publicity: Publicity::Private,
30633063+ deprecation: Deprecation::NotDeprecated,
30643064+ type_: record_type,
30653065+ variant: ValueConstructorVariant::LocalVariable {
30663066+ location: record_location,
30673067+ origin: VariableOrigin::generated(),
30683068+ },
30693069+ },
30703070+ name: RECORD_UPDATE_VARIABLE.into(),
30713071+ };
30723072+ (record_var, Some(Box::new(record_assignment)))
30683073 };
3069307430703075 // infer the fields of the variant we want to update
···30763081 Ok(TypedExpr::RecordUpdate {
30773082 location,
30783083 type_: variant.retn,
30793079- record: Box::new(record_assignment),
30843084+ record_assignment,
30803085 constructor: Box::new(typed_constructor),
30813086 args,
30823087 })