diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index 534203ded5bac9a87d4b97ff82fd894fedc66d40..ac9ce9c63323c9a21cafd5d1412eb7ba617b33fd 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -1032,13 +1032,6 @@ void ETSChecker::CheckFunctionSignatureAnnotations(const ArenaVectorParams()) { - std::ignore = SetUpParameterType(typeParam); - CheckAnnotations(typeParam->Annotations()); - } - } - for (auto *param : params) { if (param->IsETSParameterExpression()) { CheckAnnotations(param->AsETSParameterExpression()->Annotations()); @@ -1048,6 +1041,12 @@ void ETSChecker::CheckFunctionSignatureAnnotations(const ArenaVectorParams()) { + CheckAnnotations(typeParam->Annotations()); + } + } + if (returnTypeAnnotation != nullptr) { ValidateThisUsage(returnTypeAnnotation); CheckAnnotations(returnTypeAnnotation->Annotations()); diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index d02274ff1f13745ccda4c8c013f8aaffb699c180..9478da06faf7c6cea6dc724a8f2b46a59c9ef3c1 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -713,13 +713,8 @@ void ScopeInitTyped::VisitTSTypeParameter(ir::TSTypeParameter *typeParam) void ScopeInitTyped::VisitTSTypeParameterDeclaration(ir::TSTypeParameterDeclaration *paramDecl) { - if (VarBinder()->GetScope()->IsFunctionParamScope() && VarBinder()->GetScope()->Parent()->IsLocalScope()) { - BindScopeNode(VarBinder()->GetScope()->Parent()->AsLocalScope(), paramDecl); - Iterate(paramDecl); - } else { - BindScopeNode(VarBinder()->GetScope()->AsLocalScope(), paramDecl); - Iterate(paramDecl); - } + BindScopeNode(VarBinder()->GetScope()->AsLocalScope(), paramDecl); + Iterate(paramDecl); } void ScopeInitTyped::VisitClassDefinition(ir::ClassDefinition *classDef) @@ -1240,9 +1235,7 @@ void InitScopesPhaseETS::VisitETSNewClassInstanceExpression(ir::ETSNewClassInsta void InitScopesPhaseETS::VisitTSTypeParameter(ir::TSTypeParameter *typeParam) { - if (typeParam->Name()->Variable() != nullptr && - VarBinder()->GetScope()->FindLocal(typeParam->Name()->Name(), - varbinder::ResolveBindingOptions::ALL_VARIABLES) != nullptr) { + if (typeParam->Name()->Variable() != nullptr) { return; } auto [decl, var] = diff --git a/ets2panda/ir/ets/etsFunctionType.cpp b/ets2panda/ir/ets/etsFunctionType.cpp index ebe73b6a5273dc9a6c76bac06f4b8107161a7883..5276c7d7a3a5a2abb53ca4e26d4d149d36e4e92a 100644 --- a/ets2panda/ir/ets/etsFunctionType.cpp +++ b/ets2panda/ir/ets/etsFunctionType.cpp @@ -49,13 +49,7 @@ void ETSFunctionType::Dump(ir::SrcDumper *dumper) const for (auto *anno : Annotations()) { anno->Dump(dumper); } - dumper->Add("("); - if (TypeParams() != nullptr) { - dumper->Add("<"); - TypeParams()->Dump(dumper); - dumper->Add(">"); - } - dumper->Add("("); + dumper->Add("(("); for (auto *param : Params()) { param->Dump(dumper); if (param != Params().back()) { @@ -64,6 +58,10 @@ void ETSFunctionType::Dump(ir::SrcDumper *dumper) const } dumper->Add(")"); + if (TypeParams() != nullptr) { + TypeParams()->Dump(dumper); + } + if (ReturnType() != nullptr) { dumper->Add("=> "); ReturnType()->Dump(dumper); diff --git a/ets2panda/ir/ts/tsTypeParameter.cpp b/ets2panda/ir/ts/tsTypeParameter.cpp index 2483117d15ada0b2cc97d08f8d0a37efc4ceb524..e4a489d11107e54655479c93ad70d0e5ca2c385a 100644 --- a/ets2panda/ir/ts/tsTypeParameter.cpp +++ b/ets2panda/ir/ts/tsTypeParameter.cpp @@ -152,24 +152,6 @@ TSTypeParameter *TSTypeParameter::Construct(ArenaAllocator *allocator) return allocator->New(nullptr, nullptr, nullptr, allocator); } -TSTypeParameter *TSTypeParameter::Clone(ArenaAllocator *allocator, AstNode *parent) -{ - auto *clone = allocator->New( - name_->Clone(allocator, this), constraint_ == nullptr ? nullptr : constraint_->Clone(allocator, this), - defaultType_ == nullptr ? nullptr : defaultType_->Clone(allocator, this), allocator); - clone->SetParent(parent); - clone->SetRange(range_.GetRange()); - - if (!Annotations().empty()) { - ArenaVector annotationUsages {allocator->Adapter()}; - for (auto *annotationUsage : Annotations()) { - annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage()); - } - clone->SetAnnotations(std::move(annotationUsages)); - } - return clone; -} - void TSTypeParameter::CopyTo(AstNode *other) const { auto otherImpl = other->AsTSTypeParameter(); diff --git a/ets2panda/ir/ts/tsTypeParameter.h b/ets2panda/ir/ts/tsTypeParameter.h index edb12492099ef658616d05ad3685bbb391414b55..97c92bf6da7595460cd48fe7f023b1141e0447c5 100644 --- a/ets2panda/ir/ts/tsTypeParameter.h +++ b/ets2panda/ir/ts/tsTypeParameter.h @@ -119,7 +119,6 @@ public: } TSTypeParameter *Construct(ArenaAllocator *allocator) override; - TSTypeParameter *Clone(ArenaAllocator *allocator, AstNode *parent) override; void CopyTo(AstNode *other) const override; private: diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp index 78bd362f4ed32df7bdfdb7c197a4a58fc8277624..1ae682e17f96f248d6503893e11c1186593749c5 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.cpp @@ -92,21 +92,6 @@ TSTypeParameterDeclaration *TSTypeParameterDeclaration::Construct(ArenaAllocator return allocator->New(std::move(params), 0); } -TSTypeParameterDeclaration *TSTypeParameterDeclaration::Clone(ArenaAllocator *allocator, AstNode *parent) -{ - ArenaVector params(allocator->Adapter()); - for (auto *param : params_) { - params.push_back(param->Clone(allocator, this)->AsTSTypeParameter()); - } - - auto *const clone = allocator->New(std::move(params), requiredParams_); - if (parent != nullptr) { - clone->SetParent(parent); - } - clone->SetRange(range_.GetRange()); - return clone; -} - void TSTypeParameterDeclaration::CopyTo(AstNode *other) const { auto otherImpl = other->AsTSTypeParameterDeclaration(); diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.h b/ets2panda/ir/ts/tsTypeParameterDeclaration.h index 31a3b786fbb791351af438704ee5b7559aa8cd60..b1076a3d74ac79266f691d158cd58385f9600b46 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.h +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.h @@ -98,7 +98,6 @@ public: void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; - TSTypeParameterDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Accept(ASTVisitorT *v) override { diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index d9970074638f4d87b7610d70336eedddf0b3a7ca..c3ef0fd3220e649df71f9822651c3d75a8acf406 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2156,9 +2156,6 @@ ir::TSTypeParameter *ETSParser::ParseTypeParameter([[maybe_unused]] TypeAnnotati } auto saveLoc = Lexer()->GetToken().Start(); auto *paramIdent = ExpectIdentifier(false, false, *options); - if (paramIdent == nullptr) { - return nullptr; - } ir::TypeNode *constraint = nullptr; if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_EXTENDS) { diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 4e528d725fbac7789f8d80ac635e6d349ebf2aaa..ba7394ef40947dff72f4da3213a403314258ead9 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -264,8 +264,7 @@ private: ir::TypeNode *ParseUnionType(ir::TypeNode *firstType); ir::TypeNode *GetTypeAnnotationOfPrimitiveType(lexer::TokenType tokenType, TypeAnnotationParsingOptions *options); ir::TypeNode *ParseWildcardType(TypeAnnotationParsingOptions *options); - ir::TypeNode *ParseFunctionType(TypeAnnotationParsingOptions *options, - ir::TSTypeParameterDeclaration *typeParamDecl = nullptr); + ir::TypeNode *ParseFunctionType(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseETSTupleType(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseTsArrayType(ir::TypeNode *typeNode, TypeAnnotationParsingOptions *options); bool ParseTriplePeriod(bool spreadTypePresent); @@ -276,14 +275,11 @@ private: bool IsArrowFunctionExpressionStart(); ir::ArrowFunctionExpression *ParseArrowFunctionExpression(); void ReportIfVarDeclaration(VariableParsingFlags flags) override; - ir::TypeNode *ParsePotentialFunctionalType(TypeAnnotationParsingOptions *options, - ir::TSTypeParameterDeclaration *typeParamDecl = nullptr); + ir::TypeNode *ParsePotentialFunctionalType(TypeAnnotationParsingOptions *options); std::pair ParseNonNullableType(TypeAnnotationParsingOptions *options); void CheckForConditionalTypeError(TypeAnnotationParsingOptions options, lexer::TokenType tokenType); std::pair GetTypeAnnotationFromToken(TypeAnnotationParsingOptions *options); - std::pair GetTypeAnnotationFromArrowFunction(TypeAnnotationParsingOptions *options); - std::pair GetTypeAnnotationFromParentheses( - TypeAnnotationParsingOptions *options, ir::TSTypeParameterDeclaration *typeParamDecl = nullptr); + std::pair GetTypeAnnotationFromParentheses(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseLiteralIdent(TypeAnnotationParsingOptions *options); void ParseRightParenthesis(TypeAnnotationParsingOptions *options, ir::TypeNode *&typeAnnotation, lexer::LexerPosition savedPos); @@ -437,6 +433,7 @@ private: ir::Expression *ParseExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS) override; ir::Expression *ParseExpressionOrTypeAnnotation(lexer::TokenType type, ExpressionParseFlags flags) override; ir::Expression *ParsePotentialExpressionSequence(ir::Expression *expr, ExpressionParseFlags flags) override; + ir::Expression *ParseGenericLambdaOrTypeAssertion(); ir::ModifierFlags ParseTypeVarianceModifier(TypeAnnotationParsingOptions *const options); bool IsExportedDeclaration(ir::ModifierFlags memberModifiers); ir::Statement *ParseTopLevelDeclStatement(StatementParsingFlags flags); diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index 2a7e6dc5d023e344c3fecfb43dd648a0f3c7d2ba..4511855c4402e83ea20750dc00323eaa7587bacf 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -824,6 +824,29 @@ void ETSParser::ValidateInstanceOfExpression(ir::Expression *expr) } } +ir::Expression *ETSParser::ParseGenericLambdaOrTypeAssertion() +{ + ES2PANDA_ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); + const auto savedPosition = Lexer()->Save(); + const auto start = Lexer()->GetToken().Start(); + const auto arrowStart = DiagnosticEngine().Save(); + if (ir::Expression *expr = ParseGenericArrowFunction(); expr != nullptr) { + LogError(diagnostic::GENERIC_LAMBDA_NOT_SUPPORTED, util::DiagnosticMessageParams {}, start); + return AllocBrokenExpression(expr->Range()); + } + const auto afterArrow = DiagnosticEngine().Save(); + Lexer()->Rewind(savedPosition); + if (const ir::Expression *typeAssertion = ParseTypeAssertion(); typeAssertion != nullptr) { + DiagnosticEngine().UndoRange(arrowStart, afterArrow); + LogError(diagnostic::TS_TYPE_ASSERTION, util::DiagnosticMessageParams {}, start); + ES2PANDA_ASSERT(DiagnosticEngine().IsAnyError()); + return AllocBrokenExpression(typeAssertion->Range()); + } + DiagnosticEngine().Rollback(afterArrow); + ES2PANDA_ASSERT(DiagnosticEngine().IsAnyError()); + return AllocBrokenExpression(lexer::SourceRange {start, Lexer()->GetToken().End()}); +} + // NOLINTNEXTLINE(google-default-arguments) ir::Expression *ETSParser::ParseExpression(ExpressionParseFlags flags) { @@ -831,7 +854,6 @@ ir::Expression *ETSParser::ParseExpression(ExpressionParseFlags flags) if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_AT)) { annotations = ParseAnnotations(false); } - const auto savedPosition = Lexer()->Save(); const auto start = Lexer()->GetToken().Start(); if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_YIELD && (flags & ExpressionParseFlags::DISALLOW_YIELD) == 0U) { @@ -840,21 +862,7 @@ ir::Expression *ETSParser::ParseExpression(ExpressionParseFlags flags) return ParsePotentialExpressionSequence(yieldExpr, flags); } if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { - const auto arrowStart = DiagnosticEngine().Save(); - if (ir::Expression *expr = ParseGenericArrowFunction(true); expr != nullptr && !expr->IsBrokenExpression()) { - return expr; - } - const auto afterArrow = DiagnosticEngine().Save(); - Lexer()->Rewind(savedPosition); - if (const ir::Expression *typeAssertion = ParseTypeAssertion(); typeAssertion != nullptr) { - DiagnosticEngine().UndoRange(arrowStart, afterArrow); - LogError(diagnostic::TS_TYPE_ASSERTION, util::DiagnosticMessageParams {}, start); - ES2PANDA_ASSERT(DiagnosticEngine().IsAnyError()); - return AllocBrokenExpression(typeAssertion->Range()); - } - DiagnosticEngine().Rollback(afterArrow); - ES2PANDA_ASSERT(DiagnosticEngine().IsAnyError()); - return AllocBrokenExpression(lexer::SourceRange {start, Lexer()->GetToken().End()}); + return ParseGenericLambdaOrTypeAssertion(); } ir::Expression *unaryExpressionNode = ParseUnaryOrPrefixUpdateExpression(flags); diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 209397b1dfd8a24599c3ead32b37462f3269c994..c6aee1ee1fbc55c66809569acb98c30f16cd6d74 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -189,8 +189,7 @@ ir::TypeNode *ETSParser::ParseWildcardType(TypeAnnotationParsingOptions *options return wildcardType; } -ir::TypeNode *ETSParser::ParseFunctionType(TypeAnnotationParsingOptions *options, - ir::TSTypeParameterDeclaration *typeParamDecl) +ir::TypeNode *ETSParser::ParseFunctionType(TypeAnnotationParsingOptions *options) { auto startLoc = Lexer()->GetToken().Start(); auto params = ParseFunctionParams(); @@ -214,7 +213,7 @@ ir::TypeNode *ETSParser::ParseFunctionType(TypeAnnotationParsingOptions *options } auto *funcType = AllocNode( - ir::FunctionSignature(typeParamDecl, std::move(params), returnTypeAnnotation, hasReceiver), + ir::FunctionSignature(nullptr, std::move(params), returnTypeAnnotation, hasReceiver), ir::ScriptFunctionFlags::NONE, Allocator()); funcType->SetRange({startLoc, returnTypeAnnotation->End()}); @@ -274,8 +273,7 @@ ir::TypeNode *ETSParser::ParseETSTupleType(TypeAnnotationParsingOptions *const o } // Helper function for ETSParser::GetTypeAnnotationFromToken(...) method -ir::TypeNode *ETSParser::ParsePotentialFunctionalType(TypeAnnotationParsingOptions *options, - ir::TSTypeParameterDeclaration *typeParamDecl) +ir::TypeNode *ETSParser::ParsePotentialFunctionalType(TypeAnnotationParsingOptions *options) { auto savePos = Lexer()->Save(); ExpectToken(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); @@ -305,7 +303,7 @@ ir::TypeNode *ETSParser::ParsePotentialFunctionalType(TypeAnnotationParsingOptio GetContext().Status() |= (ParserStatus::ALLOW_DEFAULT_VALUE | ParserStatus::ALLOW_RECEIVER); // '(' is consumed in `ParseFunctionType` Lexer()->Rewind(savePos); - auto typeAnnotation = ParseFunctionType(options, typeParamDecl); + auto typeAnnotation = ParseFunctionType(options); GetContext().Status() ^= (ParserStatus::ALLOW_DEFAULT_VALUE | ParserStatus::ALLOW_RECEIVER); return typeAnnotation; } @@ -369,9 +367,6 @@ std::pair ETSParser::GetTypeAnnotationFromToken(TypeAnnota case lexer::TokenType::PUNCTUATOR_BACK_TICK: { return std::make_pair(ParseMultilineString(), true); } - case lexer::TokenType::PUNCTUATOR_LESS_THAN: { - return GetTypeAnnotationFromArrowFunction(options); - } case lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS: { return GetTypeAnnotationFromParentheses(options); } @@ -402,31 +397,11 @@ std::pair ETSParser::GetTypeAnnotationFromToken(TypeAnnota return std::make_pair(typeAnnotation, true); } -std::pair ETSParser::GetTypeAnnotationFromArrowFunction(TypeAnnotationParsingOptions *options) -{ - ES2PANDA_ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); - lexer::LexerPosition savedPos = Lexer()->Save(); - - auto typeParamDeclOptions = TypeAnnotationParsingOptions::NO_OPTS; - ir::TSTypeParameterDeclaration *typeParamDecl = ParseTypeParameterDeclaration(&typeParamDeclOptions); - if (typeParamDecl == nullptr) { - Lexer()->Rewind(savedPos); - return {nullptr, true}; - } - - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS) { - Lexer()->Rewind(savedPos); - return {nullptr, true}; - } - return GetTypeAnnotationFromParentheses(options, typeParamDecl); -} - -std::pair ETSParser::GetTypeAnnotationFromParentheses( - TypeAnnotationParsingOptions *options, ir::TSTypeParameterDeclaration *typeParamDecl) +std::pair ETSParser::GetTypeAnnotationFromParentheses(TypeAnnotationParsingOptions *options) { auto startLoc = Lexer()->GetToken().Start(); - ir::TypeNode *typeAnnotation = ParsePotentialFunctionalType(options, typeParamDecl); + ir::TypeNode *typeAnnotation = ParsePotentialFunctionalType(options); if (typeAnnotation != nullptr) { typeAnnotation->SetStart(startLoc); return std::make_pair(typeAnnotation, true); diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index 90150e77c62e99550c8d0618cebd32a12d6344c3..5513665d3fb75529fbeba193c60f2c27f253d414 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -196,7 +196,7 @@ ir::TSTypeAssertion *TypedParser::ParseTypeAssertion() Lexer()->NextToken(); // eat '>' ir::Expression *expression = ParseExpression(); - if (expression == nullptr || expression->IsBrokenExpression()) { + if (expression == nullptr) { return nullptr; } auto *typeAssertion = AllocNode(typeAnnotation, expression); @@ -234,7 +234,7 @@ ir::Statement *TypedParser::ParseNamespace([[maybe_unused]] ir::ModifierFlags fl return ParseModuleDeclaration(); } -ir::ArrowFunctionExpression *TypedParser::ParseGenericArrowFunction(bool isThrowError) +ir::ArrowFunctionExpression *TypedParser::ParseGenericArrowFunction() { ArrowFunctionContext arrowFunctionContext(this, false); @@ -245,10 +245,6 @@ ir::ArrowFunctionExpression *TypedParser::ParseGenericArrowFunction(bool isThrow ir::TSTypeParameterDeclaration *typeParamDecl = ParseTypeParameterDeclaration(&typeParamDeclOptions); if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS) { - if (isThrowError) { - LogError(diagnostic::UNEXPECTED_TOKEN_EXPECTED_PARAM, - {TokenToString(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS)}); - } return nullptr; } @@ -268,9 +264,6 @@ ir::ArrowFunctionExpression *TypedParser::ParseGenericArrowFunction(bool isThrow } if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_ARROW) { - if (isThrowError) { - LogError(diagnostic::UNEXPECTED_TOKEN_EXPECTED_PARAM, {TokenToString(lexer::TokenType::PUNCTUATOR_ARROW)}); - } return nullptr; } diff --git a/ets2panda/parser/TypedParser.h b/ets2panda/parser/TypedParser.h index ec50263d42e420e7fa022d4de04cda7b54178c35..bb1379b9e51586619e4f9a587faaf4e574a5a019 100644 --- a/ets2panda/parser/TypedParser.h +++ b/ets2panda/parser/TypedParser.h @@ -41,7 +41,7 @@ protected: ArenaVector ParseTypeLiteralOrInterfaceBody(); void CheckObjectTypeForDuplicatedProperties(ir::Expression *key, ArenaVector &members); - ir::ArrowFunctionExpression *ParseGenericArrowFunction(bool isThrowError = false); + ir::ArrowFunctionExpression *ParseGenericArrowFunction(); ir::TSTypeAssertion *ParseTypeAssertion(); ir::TSTypeParameterInstantiation *ParseTypeParameterInstantiation(TypeAnnotationParsingOptions *options); diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 89cd7fa0698f0e5de84cc37f8b57832665a8f888..85cc7f0edd2b68d7fec6c20932a43edc943fda59 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -331,10 +331,6 @@ ir::ArrowFunctionExpression *ParserImpl::ParseArrowFunctionExpressionBody(ArrowF ExpectToken(lexer::TokenType::PUNCTUATOR_RIGHT_BRACE); endLoc = body->End(); } - if ((GetContext().Status() & ParserStatus::FUNCTION_HAS_RETURN_STATEMENT) != 0) { - arrowFunctionContext->AddFlag(ir::ScriptFunctionFlags::HAS_RETURN); - GetContext().Status() ^= ParserStatus::FUNCTION_HAS_RETURN_STATEMENT; - } // clang-format off funcNode = AllocNode( Allocator(), ir::ScriptFunction::ScriptFunctionData { @@ -580,10 +576,6 @@ ir::Expression *ParserImpl::ParseAssignmentExpressionHelper() ir::Expression *ParserImpl::CreateBinaryAssignmentExpression(ir::Expression *assignmentExpression, ir::Expression *lhsExpression, lexer::TokenType tokenType) { - if (assignmentExpression == nullptr) { - assignmentExpression = AllocBrokenExpression(Lexer()->GetToken().Loc()); - } - auto *binaryAssignmentExpression = AllocNode(lhsExpression, assignmentExpression, tokenType); ES2PANDA_ASSERT(binaryAssignmentExpression != nullptr); diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index e45ca21c2d23a9436926fca75bbf4528f989ca60..ed6629b8f19038e207d43b2a414e35f66046b50a 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -744,9 +744,6 @@ ir::Statement *ParserImpl::ParseExpressionStatement(StatementParsingFlags flags) } ir::Expression *exprNode = ParseExpression(ExpressionParseFlags::ACCEPT_COMMA); - if (exprNode == nullptr) { // Error processing. - return AllocBrokenStatement(Lexer()->GetToken().Loc()); - } context_.Status() = savedStatus; lexer::SourcePosition endPos = exprNode->End(); diff --git a/ets2panda/test/ast/parser/ets/generic_lambda_err1.ets b/ets2panda/test/ast/parser/ets/generic_lambda_err1.ets deleted file mode 100644 index 78a4f357d90176707804508b76383b8058b06e26..0000000000000000000000000000000000000000 --- a/ets2panda/test/ast/parser/ets/generic_lambda_err1.ets +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function main() { - let foo = < (): void => {} -} - -/* @@? 17:15 Error SyntaxError: Unexpected token '<<'. */ -/* @@? 17:17 Error SyntaxError: Unexpected token 'T'. */ -/* @@? 17:17 Error TypeError: Unresolved reference T */ -/* @@? 17:17 Error TypeError: Bad operand type, the types of the operands must be numeric, same enumeration, or boolean type. */ -/* @@? 17:22 Error SyntaxError: Unexpected token, expected an identifier. */ -/* @@? 17:22 Error SyntaxError: Expected '=>', got 'identification literal'. */ -/* @@? 17:22 Error TypeError: Unresolved reference : */ -/* @@? 17:24 Error SyntaxError: Unexpected token 'void'. */ -/* @@? 17:29 Error SyntaxError: Unexpected token '=>'. */ diff --git a/ets2panda/test/ast/parser/ets/generic_lambda_err2.ets b/ets2panda/test/ast/parser/ets/generic_lambda_err2.ets deleted file mode 100644 index 1a4ca53eb838d095b223a3775e94056ace0209e7..0000000000000000000000000000000000000000 --- a/ets2panda/test/ast/parser/ets/generic_lambda_err2.ets +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function main() { - let foo1 = (p: T): T => p; - foo1("1", 2) - foo1("1", 2) - - let foo2 = (p: T): NonNullable =>p; - - let foo3 = (p: T): T => p; - - let foo4 = (p: T, q: U): T => p; - foo4(1) - foo4(1) - foo4(1, 1) -} - -/* @@? 18:5 Error TypeError: Expected 1 arguments, got 2. */ -/* @@? 18:5 Error TypeError: No matching call signature for ("1", Int) */ -/* @@? 19:5 Error TypeError: Expected 1 type arguments, got 2 . */ -/* @@? 19:5 Error TypeError: No matching call signature for ("1", Int) */ -/* @@? 21:44 Error TypeError: Type 'T' is not compatible with the enclosing method's return type 'NonNullable' */ -/* @@? 23:20 Error TypeError: Duplicate type parameter 'T'. */ -/* @@? 26:5 Error TypeError: Expected 2 arguments, got 1. */ -/* @@? 26:5 Error TypeError: No matching call signature for (Int) */ -/* @@? 27:5 Error TypeError: Expected 2 arguments, got 1. */ -/* @@? 27:5 Error TypeError: No matching call signature for (Int) */ -/* @@? 28:5 Error TypeError: No matching call signature for (Int, Int) */ -/* @@? 28:26 Error TypeError: Type 'Int' is not compatible with type 'String' at index 2 */ diff --git a/ets2panda/test/ast/parser/ets/generic_lambda_err3.ets b/ets2panda/test/ast/parser/ets/generic_lambda_err3.ets deleted file mode 100644 index b6a314cde3b30c5332ec09fdd4ae6f3ad480bb08..0000000000000000000000000000000000000000 --- a/ets2panda/test/ast/parser/ets/generic_lambda_err3.ets +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -let foo1 = -let foo2 = () -let foo3 = ; -let foo4 = (); -function main() { - let foo5 = - let foo6 = () -} - -/* @@? 18:1 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 18:5 Error SyntaxError: Unexpected token 'foo2'. */ -/* @@? 18:5 Error TypeError: Unresolved reference foo2 */ -/* @@? 19:1 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 19:5 Error SyntaxError: Unexpected token 'foo3'. */ -/* @@? 19:5 Error TypeError: Unresolved reference foo3 */ -/* @@? 19:15 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 20:17 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 23:5 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 23:9 Error SyntaxError: Unexpected token 'foo6'. */ -/* @@? 23:9 Error TypeError: Unresolved reference foo6 */ -/* @@? 24:1 Error SyntaxError: Unexpected token, expected '=>'. */ -/* @@? 39:1 Error SyntaxError: Expected '}', got 'end of stream'. */ diff --git a/ets2panda/test/runtime/ets/generic_lambda_7.ets b/ets2panda/test/ast/parser/ets/no-generic-lambda.ets similarity index 60% rename from ets2panda/test/runtime/ets/generic_lambda_7.ets rename to ets2panda/test/ast/parser/ets/no-generic-lambda.ets index 8639b6b9d877faa841ad253c079b496a9a2c02d9..3f19f5974ab588f34638937c4b1072753c758828 100644 --- a/ets2panda/test/runtime/ets/generic_lambda_7.ets +++ b/ets2panda/test/ast/parser/ets/no-generic-lambda.ets @@ -13,20 +13,13 @@ * limitations under the License. */ -class A {} +let foo = (i: T) : void => { } +let bar = () => { } -function foo(f: (t: T) => T) { - let i1: number = 1.0 - arktest.assertEQ(f(i1), i1) - arktest.assertEQ(f(i1), i1) - let i2: string = "abc" - arktest.assertEQ(f(i2), i2) - arktest.assertEQ(f(i2), i2) - let i3: A = new A() - arktest.assertEQ(f(i3), i3) - arktest.assertEQ(f(i3), i3) -} +foo(1.0); +bar(); -function main() { - foo((t: T): T => t) -} +/* @@? 16:11 Error SyntaxError: Generic lambda expressions are not supported. */ +/* @@? 17:11 Error SyntaxError: Generic lambda expressions are not supported. */ +/* @@? 19:1 Error TypeError: This expression is not callable. */ +/* @@? 20:1 Error TypeError: This expression is not callable. */ diff --git a/ets2panda/test/ast/parser/ets/ts-type-assertion.ets b/ets2panda/test/ast/parser/ets/ts-type-assertion.ets index a54c5d887a9eccc92a04c2c1aa3c14afc5a5f422..19a04aa602008f3e88724508f6c9eb865a393832 100644 --- a/ets2panda/test/ast/parser/ets/ts-type-assertion.ets +++ b/ets2panda/test/ast/parser/ets/ts-type-assertion.ets @@ -24,4 +24,5 @@ const f = foo; /* @@? 19:11 Error SyntaxError: Type cast syntax '' is not supported, please use 'as' keyword instead */ /* @@? 20:12 Error SyntaxError: Type cast syntax '' is not supported, please use 'as' keyword instead */ /* @@? 21:11 Error SyntaxError: Type cast syntax '' is not supported, please use 'as' keyword instead */ -/* @@? 22:14 Error SyntaxError: Unexpected token, expected '('. */ +/* @@? 22:11 Error SyntaxError: Type cast syntax '' is not supported, please use 'as' keyword instead */ +/* @@? 22:14 Error SyntaxError: Type cast syntax '' is not supported, please use 'as' keyword instead */ diff --git a/ets2panda/test/runtime/ets/generic_lambda_1.ets b/ets2panda/test/runtime/ets/generic_lambda_1.ets deleted file mode 100644 index eb72549d0d39fe3abc226d2616443ad3595cff08..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/generic_lambda_1.ets +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function main() { - let foo1 = (p: T): T => p; - - // Explicitly deducing generics - arktest.assertEQ(foo1(1), 1) - arktest.assertEQ(foo1(1.5), 1.5) - arktest.assertEQ(foo1(false), false) - arktest.assertEQ(foo1("123"), "123") - - let foo1res1: [int, string] = foo1<[int, string]>([123, "123"]) - arktest.assertEQ(foo1res1[0] as int, 123) - arktest.assertEQ(foo1res1[1] as string, "123") - - let foo1res2: int[] = foo1([1, 2, 3]) - arktest.assertEQ(foo1res2[0], 1) - arktest.assertEQ(foo1res2[1], 2) - arktest.assertEQ(foo1res2[2], 3) - - let foo1res3: [[int, string], int[]] = foo1<[[int, string], int[]]>([foo1res1, foo1res2]) - arktest.assertEQ(foo1res3[0][0], 123) - arktest.assertEQ(foo1res3[0][1], "123") - arktest.assertEQ(foo1res3[1][0], 1) - arktest.assertEQ(foo1res3[1][1], 2) - arktest.assertEQ(foo1res3[1][2], 3) - - let foo1res4: ()=>void = foo1<()=>void>((): void=>{}) - foo1res4() - - // Implicit derivation of generics - arktest.assertEQ(foo1(1), 1) - arktest.assertEQ(foo1(1.5), 1.5) - arktest.assertEQ(foo1(false), false) - arktest.assertEQ(foo1("123"), "123") - - let foo1res5: Array = foo1([123, "123"]) - arktest.assertEQ(foo1res5[0] as int, 123) - arktest.assertEQ(foo1res5[1] as string, "123") - - let foo1res6: int[] = foo1([1, 2, 3]) - arktest.assertEQ(foo1res6[0], 1) - arktest.assertEQ(foo1res6[1], 2) - arktest.assertEQ(foo1res6[2], 3) -} diff --git a/ets2panda/test/runtime/ets/generic_lambda_2.ets b/ets2panda/test/runtime/ets/generic_lambda_2.ets deleted file mode 100644 index 7f4ba81276f96950a77998541165a6e325c80d2e..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/generic_lambda_2.ets +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function main() { - let foo = (p: T, q: U): [T, U] => [p, q] - - // Explicitly deducing generics - let res1 = foo(1.0, "abc") - arktest.assertEQ(res1[0], 1.0) - arktest.assertEQ(res1[1], "abc") - - let res2 = foo(new Error(), null) - arktest.assertTrue(res2[0] instanceof Error) - arktest.assertEQ(res2[1], null) - - let res3 = foo<[Double, string], [Error, null]>(res1, res2) - arktest.assertEQ(res3[0][0], 1.0) - arktest.assertEQ(res3[0][1], "abc") - arktest.assertTrue(res3[1][0] instanceof Error) - arktest.assertEQ(res3[1][1], null) - - // Implicit derivation of generics - let res4 = foo(1.0, "abc") - arktest.assertEQ(res4[0], 1.0) - arktest.assertEQ(res4[1], "abc") - - let res5 = foo(new Error(), null) - arktest.assertTrue(res5[0] instanceof Error) - arktest.assertEQ(res5[1], null) - - let res6 = foo(res1, res2) - arktest.assertEQ(res6[0][0], 1.0) - arktest.assertEQ(res6[0][1], "abc") - arktest.assertTrue(res6[1][0] instanceof Error) - arktest.assertEQ(res6[1][1], null) -} diff --git a/ets2panda/test/runtime/ets/generic_lambda_3.ets b/ets2panda/test/runtime/ets/generic_lambda_3.ets deleted file mode 100644 index 12dffa75404e0b14693927a2b291dab3d55aaf0b..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/generic_lambda_3.ets +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function main() { - let foo = (p: T) : T => { - let t: T = p - return t - } - - // Explicitly deducing generics - let res1 = foo(1) - arktest.assertEQ(res1, 1) - - let res2 = foo(1.5) - arktest.assertEQ(res2, 1.5) - - let res3 = foo("abc") - arktest.assertEQ(res3, "abc") - - // Implicit derivation of generics - let res4 = foo(1) - arktest.assertEQ(res4, 1) - - let res5 = foo(1.5) - arktest.assertEQ(res5, 1.5) - - let res6 = foo("abc") - arktest.assertEQ(res6, "abc") -} diff --git a/ets2panda/test/runtime/ets/generic_lambda_4.ets b/ets2panda/test/runtime/ets/generic_lambda_4.ets deleted file mode 100644 index d69a6c14f0e2d8ec77aa2175aef7721451c1c889..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/generic_lambda_4.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -class A {} -class B extends A {} - -function main() { - let foo = (p: T, q: U): int => { - if (p !== null && p !== undefined) { - return 0; - } else if (q !== null && q != undefined) { - return 1; - } else { - return 2; - } - } - - // Explicitly deducing generics - arktest.assertEQ(foo(new Object(), new Object()), 0) - arktest.assertEQ(foo(undefined, new Object()), 1) - arktest.assertEQ(foo(undefined, undefined), 2) - arktest.assertEQ(foo(new A(), new A()), 0) - arktest.assertEQ(foo(new B(), new A()), 0) - arktest.assertEQ(foo(new B(), new B()), 0) - - // Implicit derivation of generics - arktest.assertEQ(foo(new Object(), new Object()), 0) - arktest.assertEQ(foo(undefined, new Object()), 1) - arktest.assertEQ(foo(undefined, undefined), 2) - arktest.assertEQ(foo(new A(), new A()), 0) - arktest.assertEQ(foo(new B(), new A()), 0) - arktest.assertEQ(foo(new B(), new B()), 0) -} diff --git a/ets2panda/test/runtime/ets/generic_lambda_5.ets b/ets2panda/test/runtime/ets/generic_lambda_5.ets deleted file mode 100644 index 70089d84944472f071c27b2423161e7cc679eb3b..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/generic_lambda_5.ets +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function main() { - let foo1 = (t: int) => { - return 1; - } - arktest.assertEQ(foo1(1), 1) - - let foo2 = (t: int) => { - return t; - } - arktest.assertEQ(foo2(1), 1) - arktest.assertEQ(foo2(100), 100) - - let foo3 = (t: T) => { - return t; - } - arktest.assertEQ(foo3(1), 1) - arktest.assertEQ(foo3("123"), "123") - - let foo4 = (t: T, u: U) => { - return t; - } - arktest.assertEQ(foo4(1, 1), 1) - arktest.assertEQ(foo4(100, 1), 100) - arktest.assertEQ(foo4(100, "abc"), 100) - arktest.assertEQ(foo4("abc", 100), "abc") -} diff --git a/ets2panda/test/runtime/ets/generic_lambda_6.ets b/ets2panda/test/runtime/ets/generic_lambda_6.ets deleted file mode 100644 index af2bea6a41e2c7e2719236f213fbdaf0b27f14fe..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/generic_lambda_6.ets +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -// All testcases are set in top level without function -let foo1 = (p: T): T => p; - -// Explicitly deducing generics -arktest.assertEQ(foo1(1), 1) -arktest.assertEQ(foo1(1.5), 1.5) -arktest.assertEQ(foo1(false), false) -arktest.assertEQ(foo1("123"), "123") - -let foo1res1: [int, string] = foo1<[int, string]>([123, "123"]) -arktest.assertEQ(foo1res1[0] as int, 123) -arktest.assertEQ(foo1res1[1] as string, "123") - -let foo1res2: int[] = foo1([1, 2, 3]) -arktest.assertEQ(foo1res2[0], 1) -arktest.assertEQ(foo1res2[1], 2) -arktest.assertEQ(foo1res2[2], 3) - -let foo1res3: [[int, string], int[]] = foo1<[[int, string], int[]]>([foo1res1, foo1res2]) -arktest.assertEQ(foo1res3[0][0], 123) -arktest.assertEQ(foo1res3[0][1], "123") -arktest.assertEQ(foo1res3[1][0], 1) -arktest.assertEQ(foo1res3[1][1], 2) -arktest.assertEQ(foo1res3[1][2], 3) - -let foo1res4: ()=>void = foo1<()=>void>((): void=>{}) -foo1res4() - -// Implicit derivation of generics -arktest.assertEQ(foo1(1), 1) -arktest.assertEQ(foo1(1.5), 1.5) -arktest.assertEQ(foo1(false), false) -arktest.assertEQ(foo1("123"), "123") - -let foo1res5: Array = foo1([123, "123"]) -arktest.assertEQ(foo1res5[0] as int, 123) -arktest.assertEQ(foo1res5[1] as string, "123") - -let foo1res6: int[] = foo1([1, 2, 3]) -arktest.assertEQ(foo1res6[0], 1) -arktest.assertEQ(foo1res6[1], 2) -arktest.assertEQ(foo1res6[2], 3) - -let foo = (p: T, q: U): [T, U] => [p, q] - -// Explicitly deducing generics -let res1 = foo(1.0, "abc") -arktest.assertEQ(res1[0], 1.0) -arktest.assertEQ(res1[1], "abc") - -let res2 = foo(new Error(), null) -arktest.assertTrue(res2[0] instanceof Error) -arktest.assertEQ(res2[1], null) - -let res3 = foo<[Double, string], [Error, null]>(res1, res2) -arktest.assertEQ(res3[0][0], 1.0) -arktest.assertEQ(res3[0][1], "abc") -arktest.assertTrue(res3[1][0] instanceof Error) -arktest.assertEQ(res3[1][1], null) - -// Implicit derivation of generics -let res4 = foo(1.0, "abc") -arktest.assertEQ(res4[0], 1.0) -arktest.assertEQ(res4[1], "abc") - -let res5 = foo(new Error(), null) -arktest.assertTrue(res5[0] instanceof Error) -arktest.assertEQ(res5[1], null) - -let res6 = foo(res1, res2) -arktest.assertEQ(res6[0][0], 1.0) -arktest.assertEQ(res6[0][1], "abc") -arktest.assertTrue(res6[1][0] instanceof Error) -arktest.assertEQ(res6[1][1], null) diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index bfc4c833fee12b73b0133ec6f9476fbc1b61fa0b..f57241c504b15a55ec0637413ef5c7066c8f26e4 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -371,6 +371,10 @@ syntax: id: 314 message: "Generator functions are not supported, please use async/await mechanism for multitasking" +- name: GENERIC_LAMBDA_NOT_SUPPORTED + id: 12842 + message: "Generic lambda expressions are not supported." + - name: GETTER_FORMAL_PARAMS id: 58 message: "Getter must not have formal parameters." diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index ac209bbeb3c263f83bd6e99475c4cf0bc2e7cf1c..3e0942600a6cdba266c49ca66394989d25fd30cb 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -135,7 +135,7 @@ void ETSBinder::LookupTypeReference(ir::Identifier *ident) } } - if (ident->Variable() != nullptr || LookupInDebugInfoPlugin(ident)) { + if (LookupInDebugInfoPlugin(ident)) { return; } diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index 903b652741d54ba2da122e3a6a035e3cf68e8a65..5060dc2a00421b4892ba402dda32ef35ee25c0b9 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -509,7 +509,7 @@ Variable *FunctionParamScope::AddBinding([[maybe_unused]] ArenaAllocator *alloca [[maybe_unused]] Variable *currentVariable, [[maybe_unused]] Decl *newDecl, [[maybe_unused]] ScriptExtension extension) { - return AddLocal(allocator, currentVariable, newDecl, extension); + ES2PANDA_UNREACHABLE(); } Variable *AnnotationParamScope::AddBinding([[maybe_unused]] ArenaAllocator *allocator, diff --git a/ets2panda/varbinder/varbinder.cpp b/ets2panda/varbinder/varbinder.cpp index 0c8e39ff4ef948b13e724b95fd4cc40519e4cb4e..a905eae27e74538f52f7fdcb9dc1d570f124643a 100644 --- a/ets2panda/varbinder/varbinder.cpp +++ b/ets2panda/varbinder/varbinder.cpp @@ -502,7 +502,6 @@ void VarBinder::VisitScriptFunctionWithPotentialTypeParams(ir::ScriptFunction *f { if (func->TypeParams() != nullptr) { auto typeParamScopeCtx = LexicalScope::Enter(this, func->TypeParams()->Scope()); - ResolveReferences(func->TypeParams()); VisitScriptFunction(func); return; }