From 732ebf2aeb59e25307986014a55e63281b1415f1 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 30 Jan 2015 18:20:26 -0800 Subject: [PATCH] fix crash in getReturnTypeFromFunctionBody if function declaration is incomplete and does not have body --- src/compiler/checker.ts | 3 +++ .../fourslash/errorInIncompleteMethodInObjectLiteral.ts | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 tests/cases/fourslash/errorInIncompleteMethodInObjectLiteral.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ed89032b781..00b637301c8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6525,6 +6525,9 @@ module ts { function getReturnTypeFromBody(func: FunctionLikeDeclaration, contextualMapper?: TypeMapper): Type { var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func); + if (!func.body) { + return unknownType; + } if (func.body.kind !== SyntaxKind.Block) { var type = checkExpressionCached(func.body, contextualMapper); } diff --git a/tests/cases/fourslash/errorInIncompleteMethodInObjectLiteral.ts b/tests/cases/fourslash/errorInIncompleteMethodInObjectLiteral.ts new file mode 100644 index 00000000000..bd498acec5f --- /dev/null +++ b/tests/cases/fourslash/errorInIncompleteMethodInObjectLiteral.ts @@ -0,0 +1,5 @@ +/// + +//// var x: { f(): string } = { f( } + +verify.numberOfErrorsInCurrentFile(1); \ No newline at end of file