diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e5bd7828432..c293bebd745 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6248,6 +6248,12 @@ module ts { } function checkCallExpression(node: CallExpression): Type { + // Grammar checking + var hasGrammarErrorFromCheckModifierOrTypeArguments = checkGrammarModifiers(node) ? true : checkGrammarTypeArguments(node, node.typeArguments); + if (!hasGrammarErrorFromCheckModifierOrTypeArguments) { + checkGrammarArguments(node, node.arguments); + } + var signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { return voidType; @@ -9876,6 +9882,37 @@ module ts { } } + function checkGrammarForAtLeastOneTypeArgument(node: CallExpression, typeArguments: NodeArray): boolean { + if (typeArguments && typeArguments.length === 0) { + var sourceFile = getSourceFileOfNode(node); + var start = typeArguments.pos - "<".length; + var end = skipTrivia(sourceFile.text, typeArguments.end) + ">".length; + return grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Type_argument_list_cannot_be_empty); + } + } + + function checkGrammarTypeArguments(node: CallExpression, typeArguments: NodeArray): boolean { + return checkGrammarForDisallowedTrailingComma(typeArguments) || + checkGrammarForAtLeastOneTypeArgument(node, typeArguments); + } + + function checkGrammarForOmittedArgument(node: CallExpression, arguments: NodeArray): boolean { + if (arguments) { + var sourceFile = getSourceFileOfNode(node); + for (var i = 0, n = arguments.length; i < n; i++) { + var arg = arguments[i]; + if (arg.kind === SyntaxKind.OmittedExpression) { + return grammarErrorAtPos(sourceFile, arg.pos, 0, Diagnostics.Argument_expression_expected); + } + } + } + } + + function checkGrammarArguments(node: CallExpression, arguments: NodeArray): boolean { + return checkGrammarForDisallowedTrailingComma(arguments) || + checkGrammarForOmittedArgument(node, arguments); + } + function hasParseDiagnostics(sourceFile: SourceFile): boolean { return sourceFile.parseDiagnostics.length > 0; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f8d0fdfaa96..c9977d2cc1e 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -64,7 +64,7 @@ module ts { An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: DiagnosticCategory.Error, key: "An index signature must have exactly one parameter.", isEarly: true }, _0_list_cannot_be_empty: { code: 1097, category: DiagnosticCategory.Error, key: "'{0}' list cannot be empty.", isEarly: true }, Type_parameter_list_cannot_be_empty: { code: 1098, category: DiagnosticCategory.Error, key: "Type parameter list cannot be empty.", isEarly: true }, - Type_argument_list_cannot_be_empty: { code: 1099, category: DiagnosticCategory.Error, key: "Type argument list cannot be empty." }, + Type_argument_list_cannot_be_empty: { code: 1099, category: DiagnosticCategory.Error, key: "Type argument list cannot be empty.", isEarly: true }, Invalid_use_of_0_in_strict_mode: { code: 1100, category: DiagnosticCategory.Error, key: "Invalid use of '{0}' in strict mode.", isEarly: true }, with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: DiagnosticCategory.Error, key: "'with' statements are not allowed in strict mode.", isEarly: true }, delete_cannot_be_called_on_an_identifier_in_strict_mode: { code: 1102, category: DiagnosticCategory.Error, key: "'delete' cannot be called on an identifier in strict mode.", isEarly: true }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f384157169e..7caf3619cea 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -287,7 +287,8 @@ }, "Type argument list cannot be empty.": { "category": "Error", - "code": 1099 + "code": 1099, + "isEarly": true }, "Invalid use of '{0}' in strict mode.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7e6d8c7a226..a07b9856d70 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4629,9 +4629,9 @@ module ts { case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: return checkBreakOrContinueStatement(node); - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - return checkCallOrNewExpression(node); + //case SyntaxKind.CallExpression: + //case SyntaxKind.NewExpression: + //return checkCallOrNewExpression(node); case SyntaxKind.EnumDeclaration: return checkEnumDeclaration(node); case SyntaxKind.BinaryExpression: return checkBinaryExpression(node); diff --git a/tests/baselines/reference/emptyTypeArgumentList.errors.txt b/tests/baselines/reference/emptyTypeArgumentList.errors.txt index 51efea14cb1..9f252b127a1 100644 --- a/tests/baselines/reference/emptyTypeArgumentList.errors.txt +++ b/tests/baselines/reference/emptyTypeArgumentList.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty. tests/cases/compiler/emptyTypeArgumentList.ts(2,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty. ==== tests/cases/compiler/emptyTypeArgumentList.ts (2 errors) ==== function foo() { } foo<>(); - ~~ -!!! error TS1099: Type argument list cannot be empty. ~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file +!!! error TS2346: Supplied parameters do not match any signature of call target. + ~~ +!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt index 538d0abb264..799e35d0d47 100644 --- a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt +++ b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty. tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty. ==== tests/cases/compiler/emptyTypeArgumentListWithNew.ts (2 errors) ==== class foo { } new foo<>(); - ~~ -!!! error TS1099: Type argument list cannot be empty. ~~~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file +!!! error TS2346: Supplied parameters do not match any signature of call target. + ~~ +!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/missingArgument1.errors.txt b/tests/baselines/reference/missingArgument1.errors.txt index 02911e3c9b5..ba2bb0892f2 100644 --- a/tests/baselines/reference/missingArgument1.errors.txt +++ b/tests/baselines/reference/missingArgument1.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/missingArgument1.ts(1,7): error TS1135: Argument expression expected. tests/cases/compiler/missingArgument1.ts(1,1): error TS2304: Cannot find name 'foo'. tests/cases/compiler/missingArgument1.ts(1,5): error TS2304: Cannot find name 'a'. +tests/cases/compiler/missingArgument1.ts(1,7): error TS1135: Argument expression expected. tests/cases/compiler/missingArgument1.ts(1,8): error TS2304: Cannot find name 'b'. ==== tests/cases/compiler/missingArgument1.ts (4 errors) ==== foo(a,,b); - -!!! error TS1135: Argument expression expected. ~~~ !!! error TS2304: Cannot find name 'foo'. ~ !!! error TS2304: Cannot find name 'a'. + +!!! error TS1135: Argument expression expected. ~ !!! error TS2304: Cannot find name 'b'. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ArgumentList5.errors.txt b/tests/baselines/reference/parserErrorRecovery_ArgumentList5.errors.txt index 7188df192b8..5113807faa8 100644 --- a/tests/baselines/reference/parserErrorRecovery_ArgumentList5.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ArgumentList5.errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,9): error TS1009: Trailing comma not allowed. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,4): error TS2304: Cannot find name 'bar'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,8): error TS2304: Cannot find name 'a'. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,9): error TS1009: Trailing comma not allowed. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts (3 errors) ==== function foo() { bar(a,) - ~ -!!! error TS1009: Trailing comma not allowed. ~~~ !!! error TS2304: Cannot find name 'bar'. ~ !!! error TS2304: Cannot find name 'a'. + ~ +!!! error TS1009: Trailing comma not allowed. return; } \ No newline at end of file diff --git a/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt b/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt index 986f2dedf6e..76e09a1a4de 100644 --- a/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt +++ b/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,7): error TS1009: Trailing comma not allowed. -tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,8): error TS1009: Trailing comma not allowed. tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,7): error TS1009: Trailing comma not allowed. tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,8): error TS1009: Trailing comma not allowed. ==== tests/cases/compiler/trailingSeparatorInFunctionCall.ts (4 errors) ==== @@ -9,16 +9,16 @@ tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,1): error TS2346: Supp } f(1, 2, ); - ~ -!!! error TS1009: Trailing comma not allowed. ~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. + ~ +!!! error TS1009: Trailing comma not allowed. function f2(x: T, y: T) { } f2(1, 2, ); - ~ -!!! error TS1009: Trailing comma not allowed. ~~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file +!!! error TS2346: Supplied parameters do not match any signature of call target. + ~ +!!! error TS1009: Trailing comma not allowed. \ No newline at end of file