Skip to content

Commit

Permalink
fix: code generation for empty messages (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich authored Jun 7, 2024
1 parent da6a7f6 commit c65ec9b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The grammar of the unary operators has been fixed, constant and function declarations are prohibited for contracts and at the top level of Tact modules: PR [#365](https://github.com/tact-lang/tact/pull/365)
- Typos in ABI generation: : PR [#372](https://github.com/tact-lang/tact/pull/372)
- `__tact_load_address_opt` code generation: PR [#373](https://github.com/tact-lang/tact/pull/373)
- Empty messages are now correctly converted into cells: PR [#380](https://github.com/tact-lang/tact/pull/380)

## [1.3.0] - 2024-05-03

Expand Down
9 changes: 7 additions & 2 deletions src/generator/writers/writeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function writeStructConstructor(

// Generate constructor
ctx.fun(name, () => {
const sig = `(${resolveFuncType(type, ctx)}) ${name}(${args.map((v) => resolveFuncType(type.fields.find((v2) => v2.name === v)!.type, ctx) + " " + v).join(", ")})`;
const funcType = resolveFuncType(type, ctx);
const sig = `(${funcType}) ${name}(${args.map((v) => resolveFuncType(type.fields.find((v2) => v2.name === v)!.type, ctx) + " " + v).join(", ")})`;
ctx.signature(sig);
ctx.flag("inline");
ctx.context("type:" + type.name);
Expand All @@ -80,7 +81,11 @@ function writeStructConstructor(
}
}, ctx);

ctx.append(`return (${expressions.join(", ")});`);
if (expressions.length === 0 && funcType === "tuple") {
ctx.append(`return empty_tuple();`);
} else {
ctx.append(`return (${expressions.join(", ")});`);
}
});
});
return name;
Expand Down
8 changes: 4 additions & 4 deletions src/test/__snapshots__/bugs.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ exports[`bugs should deploy contract correctly 1`] = `
"$type": "received",
"message": {
"body": {
"cell": "x{178D45190000000000000000502540BE4008001C6C7938BCE1EDDD4D7179F5626FBC23A92D0521900C93D0E579C0128C1BCFDB0016E3A425A4E75B646191AC9A34FE5D050BD101A5C490F87D01C66D885D09BC1082_}",
"cell": "x{178D45190000000000000000502540BE400800C83C40F6E01D9BBE7F089633DC9A2CB62629478287ECE373E35FD9BA1EB951B30016E3A425A4E75B646191AC9A34FE5D050BD101A5C490F87D01C66D885D09BC1082_}",
"type": "cell",
},
"bounce": false,
"from": "kQAONjycXnD27qa4vPqxN94R1JaCkMgGSehyvOAJRg3n7ROk",
"to": "kQBW5ieoSEHXuEljVf_tAb_cPCvcurQZBoW1ez4bx54-Zadw",
"from": "kQBkHiB7cA7N3z-ESxnuTRZbExSjwUP2cbnxr-zdD1yo2V-4",
"to": "kQCMrikxzzvzJk9pUSrQW6p1shWQbbH02ChyDiu2JnUvInbG",
"type": "internal",
"value": "9.959886",
},
Expand All @@ -38,7 +38,7 @@ exports[`bugs should deploy contract correctly 1`] = `
},
},
"bounce": false,
"from": "kQBW5ieoSEHXuEljVf_tAb_cPCvcurQZBoW1ez4bx54-Zadw",
"from": "kQCMrikxzzvzJk9pUSrQW6p1shWQbbH02ChyDiu2JnUvInbG",
"to": "@treasure(treasure)",
"type": "internal",
"value": "9.916924834",
Expand Down
1 change: 1 addition & 0 deletions src/test/bugs/bugs.tact
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./issue42.tact";
import "./issue43.tact";
import "./issue53.tact";
import "./issue74.tact";
import "./issue117.tact";
import "./large-contract.tact";
14 changes: 14 additions & 0 deletions src/test/bugs/issue74.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
message MyMessage {
}

contract Issue74 {
receive("send") {
send(SendParameters {
to: context().sender,
value: 0,
bounce: false,
mode: SendIgnoreErrors,
body: MyMessage {}.toCell()
});
}
}

0 comments on commit c65ec9b

Please sign in to comment.