diff --git a/CHANGELOG.md b/CHANGELOG.md index b8e5e0b77..9ece4f775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/generator/writers/writeExpression.ts b/src/generator/writers/writeExpression.ts index 94304cd77..2b302a1c7 100644 --- a/src/generator/writers/writeExpression.ts +++ b/src/generator/writers/writeExpression.ts @@ -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); @@ -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; diff --git a/src/test/__snapshots__/bugs.spec.ts.snap b/src/test/__snapshots__/bugs.spec.ts.snap index 52c0f29cc..8f04b35f0 100644 --- a/src/test/__snapshots__/bugs.spec.ts.snap +++ b/src/test/__snapshots__/bugs.spec.ts.snap @@ -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", }, @@ -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", diff --git a/src/test/bugs/bugs.tact b/src/test/bugs/bugs.tact index 668e220b0..49cd9c007 100644 --- a/src/test/bugs/bugs.tact +++ b/src/test/bugs/bugs.tact @@ -1,5 +1,6 @@ import "./issue42.tact"; import "./issue43.tact"; import "./issue53.tact"; +import "./issue74.tact"; import "./issue117.tact"; import "./large-contract.tact"; \ No newline at end of file diff --git a/src/test/bugs/issue74.tact b/src/test/bugs/issue74.tact new file mode 100644 index 000000000..71a4f7ab1 --- /dev/null +++ b/src/test/bugs/issue74.tact @@ -0,0 +1,14 @@ +message MyMessage { +} + +contract Issue74 { + receive("send") { + send(SendParameters { + to: context().sender, + value: 0, + bounce: false, + mode: SendIgnoreErrors, + body: MyMessage {}.toCell() + }); + } +} \ No newline at end of file