Skip to content

Commit

Permalink
feat: destructuring of structs and messages (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich authored Oct 15, 2024
1 parent b7038c9 commit ce201fb
Show file tree
Hide file tree
Showing 32 changed files with 1,957 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Docs: the `description` property to the frontmatter of the each page for better SEO: PR [#916](https://github.com/tact-lang/tact/pull/916)
- Docs: Google Analytics tags per every page: PR [#921](https://github.com/tact-lang/tact/pull/921)
- Ability to specify a compile-time method ID expression for getters: PR [#922](https://github.com/tact-lang/tact/pull/922) and PR [#932](https://github.com/tact-lang/tact/pull/932)
- Destructuring of structs and messages: PR [#856](https://github.com/tact-lang/tact/pull/856)

### Changed

Expand Down
20 changes: 20 additions & 0 deletions src/generator/writers/writeFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,26 @@ export function writeStatement(

return;
}
case "statement_destruct": {
const t = getExpType(ctx.ctx, f.expression);
if (t.kind !== "ref") {
throwInternalCompilerError(
`invalid destruct expression kind: ${t.kind}`,
f.expression.loc,
);
}
const ty = getType(ctx.ctx, t.name);
const ids = ty.fields.map((field) => {
const id = f.identifiers.get(field.name);
return id === undefined || isWildcard(id[1])
? "_"
: funcIdOf(id[1]);
});
ctx.append(
`var (${ids.join(", ")}) = ${writeCastedExpression(f.expression, t, ctx)};`,
);
return;
}
}

throw Error("Unknown statement kind");
Expand Down
Loading

0 comments on commit ce201fb

Please sign in to comment.