Skip to content

Commit 273a54b

Browse files
authored
Merge branch 'master' into ts-to-lua-ast (#329)
* fixed compiler crash when unable to determine signature of function… (#321) * fixed compiler crash when unable to determine signature of function argument when passing a function expression * added test * Validation crash fix (#326) * fix for crash when validating assignments of arrays/tuples * added re-assignment code to tuple return test * added new tuple assignment test and fixed others * changed static methods and lambda-properties to take a context parameter by default (#322)
1 parent 3bf23bf commit 273a54b

File tree

4 files changed

+169
-135
lines changed

4 files changed

+169
-135
lines changed

src/LuaTransformer.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,13 +2427,23 @@ export class LuaTransformer {
24272427
}
24282428
}
24292429

2430-
const fromTypeReference = fromType as ts.TypeReference;
2431-
const toTypeReference = toType as ts.TypeReference;
2432-
if (fromTypeReference.typeArguments && toTypeReference.typeArguments) {
2433-
// Recurse into tuples/arrays
2434-
toTypeReference.typeArguments.forEach((t, i) => {
2435-
this.validateFunctionAssignment(node, fromTypeReference.typeArguments[i], t, toName);
2436-
});
2430+
const fromTypeNode = this.checker.typeToTypeNode(fromType);
2431+
const toTypeNode = this.checker.typeToTypeNode(toType);
2432+
2433+
if ((ts.isArrayTypeNode(toTypeNode) || ts.isTupleTypeNode(toTypeNode))
2434+
&& (ts.isArrayTypeNode(fromTypeNode) || ts.isTupleTypeNode(fromTypeNode))) {
2435+
// Recurse into arrays/tuples
2436+
const fromTypeReference = fromType as ts.TypeReference;
2437+
const toTypeReference = toType as ts.TypeReference;
2438+
const count = Math.min(fromTypeReference.typeArguments.length, toTypeReference.typeArguments.length);
2439+
for (let i = 0; i < count; ++i) {
2440+
this.validateFunctionAssignment(
2441+
node,
2442+
fromTypeReference.typeArguments[i],
2443+
toTypeReference.typeArguments[i],
2444+
toName
2445+
);
2446+
}
24372447
}
24382448

24392449
if ((toType.flags & ts.TypeFlags.Object) !== 0 && ((toType as ts.ObjectType).objectFlags & ts.ObjectFlags.ClassOrInterface) !== 0 &&

src/TSHelper.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ export class TSHelper {
382382
if (i >= 0) {
383383
const parentSignature = checker.getResolvedSignature(signatureDeclaration.parent);
384384
const parentSignatureDeclaration = parentSignature.getDeclaration();
385-
declType = checker.getTypeAtLocation(parentSignatureDeclaration.parameters[i]);
385+
if (parentSignatureDeclaration) {
386+
declType = checker.getTypeAtLocation(parentSignatureDeclaration.parameters[i]);
387+
}
386388
}
387389
} else if (ts.isReturnStatement(signatureDeclaration.parent)) {
388390
declType = this.getContainingFunctionReturnType(signatureDeclaration.parent, checker);
@@ -409,15 +411,14 @@ export class TSHelper {
409411
// Explicit 'this'
410412
return thisParameter.type && thisParameter.type.kind === ts.SyntaxKind.VoidKeyword ? ContextType.Void : ContextType.NonVoid;
411413
}
412-
if ((ts.isMethodDeclaration(signatureDeclaration) || ts.isMethodSignature(signatureDeclaration)) &&
413-
!(ts.getCombinedModifierFlags(signatureDeclaration) & ts.ModifierFlags.Static)) {
414-
// Non-static method
414+
if (ts.isMethodDeclaration(signatureDeclaration) || ts.isMethodSignature(signatureDeclaration)) {
415+
// Method
415416
return ContextType.NonVoid;
416417
}
417-
if ((ts.isPropertySignature(signatureDeclaration.parent) || ts.isPropertyDeclaration(signatureDeclaration.parent) ||
418-
ts.isPropertyAssignment(signatureDeclaration.parent)) &&
419-
!(ts.getCombinedModifierFlags(signatureDeclaration.parent) & ts.ModifierFlags.Static)) {
420-
// Non-static lambda property
418+
if (ts.isPropertySignature(signatureDeclaration.parent)
419+
|| ts.isPropertyDeclaration(signatureDeclaration.parent)
420+
|| ts.isPropertyAssignment(signatureDeclaration.parent)) {
421+
// Lambda property
421422
return ContextType.NonVoid;
422423
}
423424
if (ts.isBinaryExpression(signatureDeclaration.parent)) {

test/translation/lua/namespaceMerge.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ end
99
end
1010
function MergedClass.constructor(self)
1111
end
12-
function MergedClass.staticMethodA()
12+
function MergedClass.staticMethodA(self)
1313
end
14-
function MergedClass.staticMethodB()
15-
self.staticMethodA();
14+
function MergedClass.staticMethodB(self)
15+
self:staticMethodA();
1616
end
1717
function MergedClass.methodA(self)
1818
end
@@ -29,5 +29,5 @@ end
2929
local mergedClass = MergedClass.new(true);
3030
mergedClass:methodB();
3131
mergedClass:propertyFunc();
32-
MergedClass.staticMethodB();
32+
MergedClass:staticMethodB();
3333
MergedClass.namespaceFunc();

0 commit comments

Comments
 (0)