@@ -23,29 +23,37 @@ function transformExpressionsInReturn(
2323) : lua . Expression [ ] {
2424 const expressionType = context . checker . getTypeAtLocation ( node ) ;
2525
26- if ( ts . isCallExpression ( node ) ) {
26+ // skip type assertions
27+ // don't skip parenthesis as it may arise confusion with lua behavior (where parenthesis are significant)
28+ const innerNode = ts . skipOuterExpressions ( node , ts . OuterExpressionKinds . Assertions ) ;
29+
30+ if ( ts . isCallExpression ( innerNode ) ) {
2731 // $multi(...)
28- if ( isMultiFunctionCall ( context , node ) ) {
32+ if ( isMultiFunctionCall ( context , innerNode ) ) {
2933 // Don't allow $multi to be implicitly cast to something other than LuaMultiReturn
3034 const type = context . checker . getContextualType ( node ) ;
3135 if ( type && ! canBeMultiReturnType ( type ) ) {
32- context . diagnostics . push ( invalidMultiFunctionReturnType ( node ) ) ;
36+ context . diagnostics . push ( invalidMultiFunctionReturnType ( innerNode ) ) ;
3337 }
3438
35- let returnValues = transformArguments ( context , node . arguments ) ;
39+ let returnValues = transformArguments ( context , innerNode . arguments ) ;
3640 if ( insideTryCatch ) {
3741 returnValues = [ wrapInTable ( ...returnValues ) ] ; // Wrap results when returning inside try/catch
3842 }
3943 return returnValues ;
4044 }
4145
4246 // Force-wrap LuaMultiReturn when returning inside try/catch
43- if ( insideTryCatch && returnsMultiType ( context , node ) && ! shouldMultiReturnCallBeWrapped ( context , node ) ) {
47+ if (
48+ insideTryCatch &&
49+ returnsMultiType ( context , innerNode ) &&
50+ ! shouldMultiReturnCallBeWrapped ( context , innerNode )
51+ ) {
4452 return [ wrapInTable ( context . transformExpression ( node ) ) ] ;
4553 }
46- } else if ( isInMultiReturnFunction ( context , node ) && isMultiReturnType ( expressionType ) ) {
54+ } else if ( isInMultiReturnFunction ( context , innerNode ) && isMultiReturnType ( expressionType ) ) {
4755 // Unpack objects typed as LuaMultiReturn
48- return [ createUnpackCall ( context , context . transformExpression ( node ) , node ) ] ;
56+ return [ createUnpackCall ( context , context . transformExpression ( innerNode ) , innerNode ) ] ;
4957 }
5058
5159 return [ context . transformExpression ( node ) ] ;
0 commit comments