X Tutup
Skip to content

Multi-Return update#978

Merged
Perryvw merged 11 commits intoTypeScriptToLua:masterfrom
tomblind:multireturn-update
Feb 8, 2021
Merged

Multi-Return update#978
Perryvw merged 11 commits intoTypeScriptToLua:masterfrom
tomblind:multireturn-update

Conversation

@tomblind
Copy link
Collaborator

@tomblind tomblind commented Feb 7, 2021

This turned into a somewhat major refactor on the multi-return stuff, as I ran into more unhandled cases along the way.

Here's the main things this PR does:

  • Rename MultiReturn to LuaMultiReturn for consistency with other lib extensions
  • Added doc comments to multi-return stuff in lib extension declarations
  • Fixed MultiReturn not wrapped in table when assigned without spread operator #968
  • Enabled support for assigning multi-return values without destructuring, by wrapping call in a table
  • Fixed broken code generation with assignment expressions and try/catch blocks
  • Added a diagnostic for cases where $multi could be implicitly cast to something else (such as when the function explicitly defines a non-multireturn return type)

@tomblind tomblind requested review from Perryvw and lolleko February 7, 2021 01:26
}"
`;

exports[`invalid $multi call (const {} = $multi();): diagnostics 1`] = `"main.ts(2,20): error TSTL: The $multi function must be called in an expression that is returned."`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diagnostic seems unclear, would it be clearer to change it to The $multi function must be called in a return statement or variable declaration.?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what it was previously. $multi can't be called in a variable declaration, so maybe we change it to just The $multi function must be called in a return statement.

if (!ts.isArrayBindingPattern(declaration.name)) {
context.diagnostics.push(invalidMultiTypeToNonArrayBindingPattern(declaration.name));
return [];
export function multiReturnCallShouldBeWrapped(context: TransformationContext, node: ts.CallExpression) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer

Suggested change
export function multiReturnCallShouldBeWrapped(context: TransformationContext, node: ts.CallExpression) {
export function shouldMultiReturnCallBeWrapped(context: TransformationContext, node: ts.CallExpression) {

But I am also okay with the current version.

@Perryvw Perryvw merged commit eae12b6 into TypeScriptToLua:master Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MultiReturn not wrapped in table when assigned without spread operator

3 participants

X Tutup