diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 317fc2afcbd80ce89cacd11494ebb3b23deb6e3b..89d5693507ba1231e92bceed181011484b284fe7 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -135,9 +135,6 @@ bool ETSChecker::EnhanceSubstitutionForType(const ArenaVector &typeParam if (paramType->IsETSArrayType()) { return EnhanceSubstitutionForArray(typeParams, paramType->AsETSArrayType(), argumentType, substitution); } - if (paramType->IsETSFunctionType()) { - return EnhanceSubstitutionForFunction(typeParams, paramType->AsETSFunctionType(), argumentType, substitution); - } return true; } diff --git a/ets2panda/parser/ETSFormattedParser.cpp b/ets2panda/parser/ETSFormattedParser.cpp index b3acf5e5596b2743139e756cb526ab959efd903c..b999b9a7bf24de8f8993f6da689f07514d89d84a 100644 --- a/ets2panda/parser/ETSFormattedParser.cpp +++ b/ets2panda/parser/ETSFormattedParser.cpp @@ -134,7 +134,7 @@ ir::Identifier *ETSParser::ParseIdentifierFormatPlaceholder(std::optionalGetToken().Start()); - return nullptr; + return AllocBrokenExpression(Lexer()->GetToken().Loc()); } nodeFormat = GetFormatPlaceholderType(); @@ -482,7 +482,7 @@ ir::Statement *ETSParser::CreateClassDeclaration(std::string_view sourceCode, bo } default: { LogUnexpectedToken(Lexer()->GetToken()); - return nullptr; + return AllocBrokenStatement(lexer->GetToken().Start()); } } } diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index d9970074638f4d87b7610d70336eedddf0b3a7ca..2708b82ee19fa8754058462a09da47a1dc5f2435 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -753,7 +753,7 @@ ir::Statement *ETSParser::ParseTypeDeclarationAbstractFinal(bool allowStatic, ir } LogUnexpectedToken(Lexer()->GetToken()); - return nullptr; + return AllocBrokenStatement(Lexer()->GetToken().Loc()); } ir::Statement *ETSParser::ParseTypeDeclaration(bool allowStatic) @@ -1682,7 +1682,7 @@ ir::Expression *ETSParser::ParseFunctionParameterAnnotations() auto annotations = ParseAnnotations(false); auto savePos = Lexer()->GetToken().Start(); ir::Expression *result = ParseFunctionParameter(); - if (result != nullptr) { + if (result != nullptr && !result->IsBrokenExpression()) { ApplyAnnotationsToNode(result, std::move(annotations), savePos); } return result; diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index 2a7e6dc5d023e344c3fecfb43dd648a0f3c7d2ba..59775285a2f83679312f9033064c83490098f844 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -65,7 +65,7 @@ ir::Expression *ETSParser::ParseFunctionParameterExpression(ir::AnnotatedExpress auto defaultValue = ParseExpression(); if (!paramIdent->IsIdentifier()) { LogError(diagnostic::IDENTIFIER_EXPECTED); - return nullptr; + return AllocBrokenExpression(Lexer()->GetToken().Loc()); } paramExpression = AllocNode(paramIdent->AsIdentifier(), defaultValue, Allocator()); diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 209397b1dfd8a24599c3ead32b37462f3269c994..17dec93abcd601dd4d0f466bf723ef1e39a9dbbe 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -199,6 +199,7 @@ ir::TypeNode *ETSParser::ParseFunctionType(TypeAnnotationParsingOptions *options if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_ARROW)) { if (((*options) & TypeAnnotationParsingOptions::REPORT_ERROR) != 0) { LogExpectedToken(lexer::TokenType::PUNCTUATOR_ARROW); + return AllocBrokenType(Lexer()->GetToken().Loc()); } return nullptr; } @@ -436,6 +437,7 @@ std::pair ETSParser::GetTypeAnnotationFromParentheses( if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS)) { if (((*options) & TypeAnnotationParsingOptions::REPORT_ERROR) != 0) { LogExpectedToken(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); + return {AllocBrokenType(Lexer()->GetToken().Loc()), false}; } return {nullptr, false}; } diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 89cd7fa0698f0e5de84cc37f8b57832665a8f888..0b86c0984d738381efca696cbbd2b807ac717f86 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -1498,6 +1498,7 @@ ir::Expression *ParserImpl::ParseOptionalChain(ir::Expression *leftSideExpr) if (tokenType == lexer::TokenType::PUNCTUATOR_BACK_TICK || lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BACK_TICK) { LogError(diagnostic::TAGGED_TEMPLATE_LITERALS_IN_OPTIONALCHAIN); + return AllocBrokenExpression(lexer_->GetToken().Loc()); } return returnExpression; diff --git a/ets2panda/test/ast/compiler/ets/fuzzingtest1.ets b/ets2panda/test/ast/compiler/ets/fuzzingtest1.ets index 32a58853e998c5da757dd44aa0905a3cf9a08223..08bf93ddf630f27c5accb8a58f2d0d4cbd8ba160 100644 --- a/ets2panda/test/ast/compiler/ets/fuzzingtest1.ets +++ b/ets2panda/test/ast/compiler/ets/fuzzingtest1.ets @@ -16,7 +16,7 @@ // the test case is from fuzzer. /* @@ label */fuzzz./* @@ label2 */@@/* @@ label3 */@@ -/* @@@ label Error TypeError: Unresolved reference fuzzz */ -/* @@@ label2 Error SyntaxError: There is no any node to insert at the placeholder position. */ -/* @@@ label2 Error SyntaxError: Identifier expected, got '@@'. */ -/* @@@ label3 Error SyntaxError: Unexpected token '@@'. */ \ No newline at end of file +/* @@? 17:15 Error TypeError: Unresolved reference fuzzz */ +/* @@? 17:36 Error SyntaxError: There is no any node to insert at the placeholder position. */ +/* @@? 17:36 Error SyntaxError: Unexpected token '@@'. */ +/* @@? 17:53 Error SyntaxError: Unexpected token '@@'. */ diff --git a/ets2panda/test/ast/compiler/ets/returnTypeAnnotation_typeParams_nullptr.ets b/ets2panda/test/ast/compiler/ets/returnTypeAnnotation_typeParams_nullptr.ets index 6308a2528182ffca7f69fce93dbb8f1a8c72e2d1..64f4958d341625ff8da0c28b31f822b54cfacbda 100755 --- a/ets2panda/test/ast/compiler/ets/returnTypeAnnotation_typeParams_nullptr.ets +++ b/ets2panda/test/ast/compiler/ets/returnTypeAnnotation_typeParams_nullptr.ets @@ -19,7 +19,5 @@ class Arr { /* @@? 16:11 Error TypeError: Only abstract or native methods can't have body. */ /* @@? 16:24 Error TypeError: FixedArray must have only one type parameter. */ /* @@? 16:37 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 16:37 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 16:37 Error SyntaxError: Invalid Type. */ /* @@? 16:37 Error SyntaxError: Unexpected token, expected '>'. */ /* @@? 16:37 Error SyntaxError: Unexpected token '>'. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets b/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets index 49a08ff7e5c657fe249e7bb2090fec0104ec94d9..3c8a14a8176d96137d9ed63cfa37fdb31bdff8a6 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets @@ -26,11 +26,16 @@ declare class Environment { /* @@? 17:23 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 18:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 19:25 Error SyntaxError: Invalid Type. */ +/* @@? 21:16 Error TypeError: Native and Declare methods should have explicit return type. */ /* @@? 21:20 Error SyntaxError: Invalid Type. */ /* @@? 21:28 Error SyntaxError: Invalid Type. */ /* @@? 21:37 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 21:37 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 21:37 Error SyntaxError: Invalid Type. */ +/* @@? 21:39 Error SyntaxError: Unexpected token '--'. */ +/* @@? 21:41 Error SyntaxError: Unexpected token '-'. */ +/* @@? 21:42 Error SyntaxError: Unexpected token ','. */ +/* @@? 21:43 Error SyntaxError: Unexpected token ')'. */ +/* @@? 21:44 Error SyntaxError: Unexpected token ':'. */ +/* @@? 21:45 Error SyntaxError: void is a predefined type, cannot be used as an identifier */ /* @@? 22:20 Error SyntaxError: Invalid Type. */ /* @@? 23:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 23:36 Error SyntaxError: Unexpected token ','. */ diff --git a/ets2panda/test/ast/parser/ets/FixedArray/unexpected_token_38.ets b/ets2panda/test/ast/parser/ets/FixedArray/unexpected_token_38.ets index f46c984335d7ec8f5e7826f18f5c08ae13da2d26..311e9b269334ace1bfb51c801d559aebe42d6ec4 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/unexpected_token_38.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/unexpected_token_38.ets @@ -25,10 +25,8 @@ let func3: (f: (a: number, b: string) => FixedArray): FixedArray /* @@? 19:8 Error TypeError: 'void' used as type annotation. */ /* @@? 22:61 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 22:61 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 22:61 Error SyntaxError: Invalid Type. */ -/* @@? 22:61 Error SyntaxError: Unexpected token '('. */ +/* @@? 22:61 Error SyntaxError: Unexpected token '=>'. */ +/* @@? 22:63 Error SyntaxError: Unexpected token 'FixedArray'. */ /* @@? 22:63 Error TypeError: Unresolved reference FixedArray */ /* @@? 22:82 Error SyntaxError: Unexpected token, expected '('. */ /* @@? 22:116 Error SyntaxError: Unexpected token, expected ',' or ')'. */ -/* @@? 22:116 Error SyntaxError: Unexpected token, expected ')'. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_with_access_modifier03.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_with_access_modifier03.ets index c6d1285bf8ac75f6673ba770e7e0c0105e76c263..9128014805bfc66074dbdc7af9dc93730a329dc0 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_with_access_modifier03.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_with_access_modifier03.ets @@ -19,4 +19,3 @@ /* @@@ label Error SyntaxError: Unexpected token 'static'. */ /* @@@ label1 Error SyntaxError: Unexpected token '@'. */ -/* @@? 15:38 Error SyntaxError: Annotations can only be declared at the top level. */ diff --git a/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets b/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets index 3f31cfcb8cf04c96a3cb805c8e90f5f29a1ebf2b..e781375637427b39b2f3a01cfc4c58d5d51629b7 100644 --- a/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets +++ b/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets @@ -26,11 +26,16 @@ declare class Environment { /* @@? 17:23 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 18:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 19:25 Error SyntaxError: Invalid Type. */ +/* @@? 21:16 Error TypeError: Native and Declare methods should have explicit return type. */ /* @@? 21:20 Error SyntaxError: Invalid Type. */ /* @@? 21:28 Error SyntaxError: Invalid Type. */ /* @@? 21:37 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 21:37 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 21:37 Error SyntaxError: Invalid Type. */ +/* @@? 21:39 Error SyntaxError: Unexpected token '--'. */ +/* @@? 21:41 Error SyntaxError: Unexpected token '-'. */ +/* @@? 21:42 Error SyntaxError: Unexpected token ','. */ +/* @@? 21:43 Error SyntaxError: Unexpected token ')'. */ +/* @@? 21:44 Error SyntaxError: Unexpected token ':'. */ +/* @@? 21:45 Error SyntaxError: void is a predefined type, cannot be used as an identifier */ /* @@? 22:20 Error SyntaxError: Invalid Type. */ /* @@? 23:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 23:36 Error SyntaxError: Unexpected token ','. */ diff --git a/ets2panda/test/ast/parser/ets/function_implicit_return_type.ets b/ets2panda/test/ast/parser/ets/function_implicit_return_type.ets index 7412439361696493516c2cbd301dc1f86d3f1f7e..08913b18bbb2685af2e80d1ca994034db08248eb 100644 --- a/ets2panda/test/ast/parser/ets/function_implicit_return_type.ets +++ b/ets2panda/test/ast/parser/ets/function_implicit_return_type.ets @@ -24,8 +24,6 @@ let void6: (i: int ) /* @@ label */= void1 /* @@ label1 */; // CTE; need function main() {} -/* @@@ label Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@@ label Error SyntaxError: Unexpected token, expected '('. */ -/* @@@ label Error SyntaxError: Invalid Type. */ -/* @@@ label Error SyntaxError: Unexpected token '('. */ -/* @@@ label1 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 23:43 Error SyntaxError: Unexpected token, expected '=>'. */ +/* @@? 23:43 Error SyntaxError: Unexpected token '=>'. */ +/* @@? 23:45 Error SyntaxError: Unexpected token 'void1'. */ diff --git a/ets2panda/test/ast/parser/ets/invalid_decorator_usage.ets b/ets2panda/test/ast/parser/ets/invalid_decorator_usage.ets index 30b54d0ce59f4e6954c555689c85ceac7b595ec5..ce1345d02672da56f6a1077b57040cde6addb934 100644 --- a/ets2panda/test/ast/parser/ets/invalid_decorator_usage.ets +++ b/ets2panda/test/ast/parser/ets/invalid_decorator_usage.ets @@ -20,15 +20,13 @@ /* @@? 16:5 Error TypeError: 'M' type does not exist. */ /* @@? 16:16 Error TypeError: Only abstract or native methods can't have body. */ /* @@? 16:29 Error SyntaxError: Unexpected 'this' keyword in non-receiver context. */ -/* @@? 16:44 Error SyntaxError: Unexpected token, expected '('. */ +/* @@? 16:40 Error SyntaxError: Annotations are not allowed on this type of declaration. */ /* @@? 16:44 Error SyntaxError: Unexpected token, expected ',' or ')'. */ -/* @@? 16:44 Error SyntaxError: Invalid Type. */ -/* @@? 16:44 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 16:44 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 16:44 Error SyntaxError: Unexpected token, expected ',' or ')'. */ -/* @@? 16:44 Error SyntaxError: Invalid Type. */ /* @@? 16:44 Error SyntaxError: Unexpected token, expected '=>'. */ /* @@? 16:46 Error SyntaxError: Unexpected token ']'. */ +/* @@? 16:46 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 16:46 Error SyntaxError: Invalid Type. */ +/* @@? 16:48 Error SyntaxError: Unexpected token ')'. */ /* @@? 16:50 Error SyntaxError: Unexpected token '=>'. */ /* @@? 16:59 Error SyntaxError: Annotations are not allowed on this type of declaration. */ /* @@? 16:61 Error SyntaxError: Unexpected token ')'. */ diff --git a/ets2panda/test/ast/parser/ets/unexpected_token_38.ets b/ets2panda/test/ast/parser/ets/unexpected_token_38.ets index ca70ddbf8179b5406e7082bc14585f8edcfc0769..780e05d9629c60f9001974f4d2513e40cda83429 100644 --- a/ets2panda/test/ast/parser/ets/unexpected_token_38.ets +++ b/ets2panda/test/ast/parser/ets/unexpected_token_38.ets @@ -25,9 +25,7 @@ let func3: (f: (a: number, b: string) => number[]): number[] => (a: number, b: b /* @@? 19:8 Error TypeError: 'void' used as type annotation. */ /* @@? 22:51 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 22:51 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 22:51 Error SyntaxError: Invalid Type. */ -/* @@? 22:51 Error SyntaxError: Unexpected token '('. */ +/* @@? 22:51 Error SyntaxError: Unexpected token '=>'. */ +/* @@? 22:53 Error SyntaxError: Unexpected token 'number'. */ /* @@? 22:62 Error SyntaxError: Unexpected token '=>'. */ /* @@? 22:62 Error SyntaxError: Unexpected token. */ -/* @@? 22:96 Error SyntaxError: Unexpected token, expected ')'. */