New functions - mixed context overloads#291
New functions - mixed context overloads#291Perryvw merged 25 commits intoTypeScriptToLua:new-functionsfrom
Conversation
…gning to untyped vars
src/Errors.ts
Outdated
| node); | ||
| } else { | ||
| return new TranspileError(`Unsupported assignment of mixed function/method overload. ` | ||
| + `All overloads should either be functions or methods.`, |
There was a problem hiding this comment.
This error is a little missleading, how about rephrasing to 'Overloads should either all be methods, or all be functions.'
| && !(ts.getCombinedModifierFlags(sigDecl.parent) & ts.ModifierFlags.Static)) { | ||
| // Non-static lambda property | ||
| return true; | ||
| return ContextType.NonVoid; |
There was a problem hiding this comment.
I thought lambda properties are currently transpiled without context, would that not mean void type here, or do we want to change this?
There was a problem hiding this comment.
lambda properties get a dummy context (versus stand-alone lambdas, which do not). This ensures they can be called the same as methods when obfuscated behind an interface.
src/Transpiler.ts
Outdated
| const type = this.checker.getTypeAtLocation(node.expression); | ||
| const op = tsHelper.isFunctionWithContext(type, this.checker) ? ":" : "."; | ||
| const sigDecl = sig.getDeclaration(); | ||
| const op = !sigDecl || tsHelper.getDeclarationContextType(sigDecl, this.checker) !== ContextType.Void |
There was a problem hiding this comment.
Try not to abbreviate variables too much, I don't think there is a lot of abbreviations on other variable names, we should probably try to be somewhat consistent.
|
Variable names and the error message are updated. Sorry I was getting lazy there 😄 |
This update addresses issues with function overloads that mix signatures with and without context:
Now, calling the overload will correctly use dot or colon based on the resolved signature:
Additionally, assignments to and from function types that have mixed overloads are now banned. Properly validating these assignments would require manually signature matching the overloads and would add a lot of complexity for a fairly fringe-y case. The error advises using only overloads that are all functions or all methods, but not both.