diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 311fc82fac18a16ad98d2e47aba077a682daa581..c963aa30303adfb578ec0ef7a96a47918749578c 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -229,7 +229,6 @@ libes2panda_sources = [ "compiler/lowering/ets/interfaceObjectLiteralLowering.cpp", "compiler/lowering/ets/interfacePropertyDeclarations.cpp", "compiler/lowering/ets/lambdaLowering.cpp", - "compiler/lowering/ets/localClassLowering.cpp", "compiler/lowering/ets/objectIndexAccess.cpp", "compiler/lowering/ets/objectIterator.cpp", "compiler/lowering/ets/objectLiteralLowering.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index bd09554954d0b099ab6e2231ca696034cf7c411b..8d0b8e9c2ec9cc9f3391a0370bf5517f2ea923a3 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -283,7 +283,6 @@ set(ES2PANDA_LIB_SRC compiler/lowering/ets/lambdaLowering.cpp compiler/lowering/ets/restTupleLowering.cpp compiler/lowering/ets/spreadLowering.cpp - compiler/lowering/ets/localClassLowering.cpp compiler/lowering/ets/objectIndexAccess.cpp compiler/lowering/ets/objectIterator.cpp compiler/lowering/ets/interfacePropertyDeclarations.cpp diff --git a/ets2panda/REVIEWERS b/ets2panda/REVIEWERS index fb870eeee4fee1dc7dd5a278626d1ff5846d012b..fd51adbf1c4668a5ce8589b6c0bb5cfde3f1b5c1 100644 --- a/ets2panda/REVIEWERS +++ b/ets2panda/REVIEWERS @@ -94,7 +94,6 @@ /ets2panda/compiler/lowering/ets/const* @ziziziiziziz @lirismankarina ^akmaevaleksey ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/enum* @ziziziiziziz @dkofanov ^akmaevaleksey ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/lambdaLowering.cpp @Ekkoruse @gogabr ^vpukhov ^akmaevaleksey ^igelhaus ^Prof1983 -/ets2panda/compiler/lowering/ets/localClassLowering.cpp @gogabr ^akmaevaleksey ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/optionalLowering.cpp @akmaevaleksey ^vpukhov ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/spread* @ziziziiziziz @dkofanov ^akmaevaleksey ^igelhaus ^Prof1983 /ets2panda/compiler/lowering/ets/unionLowering.cpp @Ekkoruse @akmaevaleksey ^vpukhov ^igelhaus ^Prof1983 diff --git a/ets2panda/compiler/lowering/ets/localClassLowering.cpp b/ets2panda/compiler/lowering/ets/localClassLowering.cpp deleted file mode 100644 index 030b52b146fbf3a505a3dbf60d6a26f247968ea5..0000000000000000000000000000000000000000 --- a/ets2panda/compiler/lowering/ets/localClassLowering.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2023-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. - */ - -#include "localClassLowering.h" - -#include "checker/ETSchecker.h" -#include "compiler/lowering/util.h" - -namespace ark::es2panda::compiler { - -std::string_view LocalClassConstructionPhase::Name() const -{ - return "LocalClassConstructionPhase"; -} - -static ir::ClassProperty *CreateCapturedField(checker::ETSChecker *checker, const varbinder::Variable *capturedVar, - varbinder::ClassScope *scope, size_t &idx) -{ - auto *allocator = checker->Allocator(); - auto *varBinder = checker->VarBinder(); - - // Enter the lambda class instance field scope, every property will be bound to the lambda instance itself - auto fieldCtx = varbinder::LexicalScope::Enter(varBinder, scope->InstanceFieldScope()); - - // Create the name for the synthetic property node - util::UString fieldName(util::StringView("field#"), allocator); - fieldName.Append(std::to_string(idx)); - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - auto *fieldIdent = allocator->New(fieldName.View(), allocator); - - // Create the synthetic class property node - auto *field = - allocator->New(fieldIdent, nullptr, nullptr, ir::ModifierFlags::NONE, allocator, false); - fieldIdent->SetParent(field); - - // Add the declaration to the scope, and set the type based on the captured variable's scope - auto [decl, var] = varBinder->NewVarDecl(fieldIdent->Start(), fieldIdent->Name()); - var->SetScope(scope->InstanceFieldScope()); - var->AddFlag(varbinder::VariableFlags::PROPERTY); - var->SetTsType(capturedVar->TsType()); - - fieldIdent->SetVariable(var); - field->SetTsType(capturedVar->TsType()); - decl->BindNode(field); - return field; -} - -static ir::Statement *CreateCtorFieldInit(checker::ETSChecker *checker, util::StringView name, varbinder::Variable *var) -{ - // Create synthetic field initializers for the local class fields - // The node structure is the following: this.field0 = field0, where the left hand side refers to the local - // classes field, and the right hand side is refers to the constructors parameter - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - auto *allocator = checker->Allocator(); - - auto *thisExpr = allocator->New(); - auto *fieldAccessExpr = allocator->New(name, allocator); - auto *leftHandSide = util::NodeAllocator::ForceSetParent( - allocator, thisExpr, fieldAccessExpr, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - auto *rightHandSide = allocator->New(name, allocator); - rightHandSide->SetVariable(var); - auto *initializer = util::NodeAllocator::ForceSetParent( - allocator, leftHandSide, rightHandSide, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - initializer->SetTsType(var->TsType()); - return util::NodeAllocator::ForceSetParent(allocator, initializer); -} - -void LocalClassConstructionPhase::CreateClassPropertiesForCapturedVariables( - public_lib::Context *ctx, ir::ClassDefinition *classDef, ArenaSet const &capturedVars, - ArenaMap &variableMap, - ArenaMap &propertyMap) -{ - checker::ETSChecker *const checker = ctx->checker->AsETSChecker(); - size_t idx = 0; - ArenaVector properties(ctx->allocator->Adapter()); - for (auto var : capturedVars) { - ES2PANDA_ASSERT(classDef->Scope()->Type() == varbinder::ScopeType::CLASS); - auto *property = - CreateCapturedField(checker, var, reinterpret_cast(classDef->Scope()), idx); - LOG(DEBUG, ES2PANDA) << " - Creating property (" << property->Id()->Name() - << ") for captured variable: " << var->Name(); - properties.push_back(property); - variableMap[var] = property->Id()->Variable(); - propertyMap[var] = property; - idx++; - } - - classDef->AddProperties(std::move(properties)); -} - -ir::ETSParameterExpression *LocalClassConstructionPhase::CreateParam(checker::ETSChecker *const checker, - varbinder::FunctionParamScope *scope, - util::StringView name, checker::Type *type) -{ - auto newParam = checker->AddParam(name, nullptr); - newParam->SetTsType(type); - newParam->Ident()->SetTsType(type); - auto paramCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope, false); - - auto *paramVar = checker->VarBinder()->AddParamDecl(newParam); - paramVar->SetTsType(newParam->TsType()); - newParam->Ident()->SetVariable(paramVar); - return newParam; -} - -void LocalClassConstructionPhase::ModifyConstructorParameters( - public_lib::Context *ctx, ir::ClassDefinition *classDef, ArenaSet const &capturedVars, - ArenaMap &variableMap, - ArenaMap ¶meterMap) - -{ - auto *classType = classDef->TsType()->AsETSObjectType(); - checker::ETSChecker *const checker = ctx->checker->AsETSChecker(); - - for (auto *signature : classType->ConstructSignatures()) { - LOG(DEBUG, ES2PANDA) << " - Modifying Constructor: " << signature->InternalName(); - auto constructor = signature->Function(); - auto ¶meters = constructor->Params(); - auto &sigParams = signature->Params(); - signature->GetSignatureInfo()->minArgCount += capturedVars.size(); - - ES2PANDA_ASSERT(signature == constructor->Signature()); - for (auto var : capturedVars) { - auto *newParam = CreateParam(checker, constructor->Scope()->ParamScope(), var->Name(), var->TsType()); - newParam->SetParent(constructor); - // NOTE(psiket) : Moving the parameter after the 'this'. Should modify the AddParam - // to be able to insert after the this. - auto ¶mScopeParams = constructor->Scope()->ParamScope()->Params(); - auto thisParamIt = ++paramScopeParams.begin(); - paramScopeParams.insert(thisParamIt, paramScopeParams.back()); - paramScopeParams.pop_back(); - - parameters.insert(parameters.begin(), newParam); - ES2PANDA_ASSERT(newParam->Variable()->Type() == varbinder::VariableType::LOCAL); - sigParams.insert(sigParams.begin(), newParam->Ident()->Variable()->AsLocalVariable()); - parameterMap[var] = newParam->Ident()->Variable()->AsLocalVariable(); - } - reinterpret_cast(checker->VarBinder())->BuildFunctionName(constructor); - LOG(DEBUG, ES2PANDA) << " Transformed Constructor: " << signature->InternalName(); - - auto *body = constructor->Body(); - ArenaVector initStatements(ctx->allocator->Adapter()); - for (auto var : capturedVars) { - auto *propertyVar = variableMap[var]; - auto *initStatement = CreateCtorFieldInit(checker, propertyVar->Name(), propertyVar); - auto *fieldInit = initStatement->AsExpressionStatement()->GetExpression()->AsAssignmentExpression(); - auto *ctorParamVar = parameterMap[var]; - auto *fieldVar = variableMap[var]; - auto *leftHandSide = fieldInit->Left(); - leftHandSide->AsMemberExpression()->SetObjectType(classType); - leftHandSide->AsMemberExpression()->SetPropVar(fieldVar->AsLocalVariable()); - leftHandSide->AsMemberExpression()->SetIgnoreBox(); - leftHandSide->AsMemberExpression()->SetTsType(fieldVar->TsType()); - leftHandSide->AsMemberExpression()->Object()->SetTsType(classType); - fieldInit->Right()->AsIdentifier()->SetVariable(ctorParamVar); - fieldInit->Right()->SetTsType(ctorParamVar->TsType()); - initStatement->SetParent(body); - initStatements.push_back(initStatement); - } - if (body != nullptr && body->IsBlockStatement()) { - auto &statements = body->AsBlockStatement()->Statements(); - statements.insert(statements.begin(), initStatements.begin(), initStatements.end()); - } - } -} - -void LocalClassConstructionPhase::RemapReferencesFromCapturedVariablesToClassProperties( - ir::ClassDefinition *classDef, ArenaMap &variableMap) -{ - auto *classType = classDef->TsType()->AsETSObjectType(); - auto remapCapturedVariables = [&variableMap](ir::AstNode *childNode) { - if (childNode->Type() == ir::AstNodeType::IDENTIFIER) { - LOG(DEBUG, ES2PANDA) << " checking var:" << (void *)childNode; - const auto &mapIt = variableMap.find(childNode->AsIdentifier()->Variable()); - if (mapIt != variableMap.end()) { - LOG(DEBUG, ES2PANDA) << " Remap: " << childNode->AsIdentifier()->Name() - << " (identifier:" << (void *)childNode - << ") variable:" << (void *)childNode->AsIdentifier()->Variable() - << " -> property variable:" << (void *)mapIt->second; - childNode->AsIdentifier()->SetVariable(mapIt->second); - } else { - } - } - }; - - for (auto *it : classDef->Body()) { - if (it->IsMethodDefinition() && !it->AsMethodDefinition()->IsConstructor()) { - LOG(DEBUG, ES2PANDA) << " - Rebinding variable rerferences in: " - << it->AsMethodDefinition()->Id()->Name().Mutf8().c_str(); - if (it->AsMethodDefinition()->Function()->Body() == nullptr && - it->AsMethodDefinition()->AsyncPairMethod() != nullptr) { - it->AsMethodDefinition()->AsyncPairMethod()->Function()->Body()->IterateRecursively( - remapCapturedVariables); - } else { - it->AsMethodDefinition()->Function()->Body()->IterateRecursively(remapCapturedVariables); - } - } - } - // Since the constructor with zero parameter is not listed in the class_def body the constructors - // processed separately - for (auto *signature : classType->ConstructSignatures()) { - auto *constructor = signature->Function(); - LOG(DEBUG, ES2PANDA) << " - Rebinding variable rerferences in: " << constructor->Id()->Name(); - if (constructor->Body() != nullptr) { - constructor->Body()->IterateRecursively(remapCapturedVariables); - } - } -} - -void LocalClassConstructionPhase::HandleLocalClass( - public_lib::Context *ctx, - ArenaUnorderedMap> &capturedVarsMap, - ir::ClassDefinition *classDef) -{ - LOG(DEBUG, ES2PANDA) << "Altering local class with the captured variables: " << classDef->InternalName(); - auto capturedVars = FindCaptured(ctx->allocator, classDef); - // Map the captured variable to the variable of the class property - ArenaMap variableMap(ctx->allocator->Adapter()); - // Map the captured variable to the class property - ArenaMap propertyMap(ctx->allocator->Adapter()); - // Map the captured variable to the constructor parameter - ArenaMap parameterMap(ctx->allocator->Adapter()); - - CreateClassPropertiesForCapturedVariables(ctx, classDef, capturedVars, variableMap, propertyMap); - ModifyConstructorParameters(ctx, classDef, capturedVars, variableMap, parameterMap); - RemapReferencesFromCapturedVariablesToClassProperties(classDef, variableMap); - capturedVarsMap.emplace(classDef, std::move(capturedVars)); -} - -bool LocalClassConstructionPhase::PerformForModule(public_lib::Context *ctx, parser::Program *program) -{ - checker::ETSChecker *const checker = ctx->checker->AsETSChecker(); - ArenaUnorderedMap> capturedVarsMap { - ctx->allocator->Adapter()}; - - program->Ast()->IterateRecursivelyPostorder([&](ir::AstNode *ast) { - if (ast->IsClassDefinition() && ast->AsClassDefinition()->IsLocal()) { - HandleLocalClass(ctx, capturedVarsMap, ast->AsClassDefinition()); - } - }); - - // Alter the instantiations - auto handleLocalClassInstantiation = [ctx, checker, &capturedVarsMap](ir::ClassDefinition *classDef, - ir::ETSNewClassInstanceExpression *newExpr) { - LOG(DEBUG, ES2PANDA) << "Instantiating local class: " << classDef->Ident()->Name(); - auto capturedVarsIt = capturedVarsMap.find(classDef); - ES2PANDA_ASSERT(capturedVarsIt != capturedVarsMap.cend()); - auto &capturedVars = capturedVarsIt->second; - for (auto *var : capturedVars) { - LOG(DEBUG, ES2PANDA) << " - Extending constructor argument with captured variable: " << var->Name(); - - auto *param = checker->AllocNode(var->Name(), ctx->allocator); - param->SetVariable(var); - param->SetIgnoreBox(); - param->SetTsType(param->Variable()->TsType()); - param->SetParent(newExpr); - newExpr->AddToArgumentsFront(param); - } - }; - - program->Ast()->IterateRecursivelyPostorder([&](ir::AstNode *ast) { - if (ast->IsETSNewClassInstanceExpression()) { - auto *newExpr = ast->AsETSNewClassInstanceExpression(); - checker::Type *calleeType = newExpr->GetTypeRef()->Check(checker); - - ES2PANDA_ASSERT(calleeType->IsETSObjectType()); - auto *calleeObj = calleeType->AsETSObjectType(); - if (!calleeObj->GetDeclNode()->IsClassDefinition()) { - return; - } - - auto *classDef = calleeObj->GetDeclNode()->AsClassDefinition(); - if (classDef->IsLocal()) { - handleLocalClassInstantiation(classDef, newExpr); - } - } - }); - - return true; -} - -} // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/localClassLowering.h b/ets2panda/compiler/lowering/ets/localClassLowering.h deleted file mode 100644 index 783993cf471bc9b8755a3b9040ff6e664e922247..0000000000000000000000000000000000000000 --- a/ets2panda/compiler/lowering/ets/localClassLowering.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2023-2024 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. - */ - -#ifndef ES2PANDA_COMPILER_LOWERING_LOCAL_CLASS_LOWERING_H -#define ES2PANDA_COMPILER_LOWERING_LOCAL_CLASS_LOWERING_H - -#include "compiler/lowering/phase.h" - -namespace ark::es2panda::compiler { - -class LocalClassConstructionPhase : public PhaseForBodies { -public: - std::string_view Name() const override; - bool PerformForModule(public_lib::Context *ctx, parser::Program *program) override; - -protected: - void CreateClassPropertiesForCapturedVariables(public_lib::Context *ctx, ir::ClassDefinition *classDef, - ArenaSet const &capturedVars, - ArenaMap &variableMap, - ArenaMap &propertyMap); - - void ModifyConstructorParameters(public_lib::Context *ctx, ir::ClassDefinition *classDef, - ArenaSet const &capturedVars, - ArenaMap &variableMap, - ArenaMap ¶meterMap); - - void RemapReferencesFromCapturedVariablesToClassProperties( - ir::ClassDefinition *classDef, ArenaMap &variableMap); - - void HandleLocalClass(public_lib::Context *ctx, - ArenaUnorderedMap> &capturedVarsMap, - ir::ClassDefinition *classDef); - - ir::ETSParameterExpression *CreateParam(checker::ETSChecker *const checker, varbinder::FunctionParamScope *scope, - util::StringView name, checker::Type *type); -}; - -} // namespace ark::es2panda::compiler - -#endif diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index 2afb9fd65ff6a8727010d7927b834865b37dba99..a54738b1fcf2365bbb95c092a520f6e399db9987 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -37,7 +37,6 @@ #include "compiler/lowering/ets/interfaceObjectLiteralLowering.h" #include "compiler/lowering/ets/interfacePropertyDeclarations.h" #include "compiler/lowering/ets/lambdaLowering.h" -#include "compiler/lowering/ets/localClassLowering.h" #include "compiler/lowering/ets/objectIndexAccess.h" #include "compiler/lowering/ets/objectIterator.h" #include "compiler/lowering/ets/objectLiteralLowering.h" @@ -100,7 +99,6 @@ static DefaultParametersLowering g_defaultParametersLowering; static DefaultParametersInConstructorLowering g_defaultParametersInConstructorLowering; static OptionalArgumentsLowering g_optionalArgumentsLowering; static TopLevelStatements g_topLevelStatements; -static LocalClassConstructionPhase g_localClassLowering; static StringComparisonLowering g_stringComparisonLowering; static StringConstantsLowering g_stringConstantsLowering; static PartialExportClassGen g_partialExportClassGen; @@ -164,7 +162,6 @@ std::vector GetETSPhaseList() &g_lambdaConversionPhase, &g_unionLowering, &g_expandBracketsPhase, - &g_localClassLowering, &g_interfaceObjectLiteralLowering, &g_objectLiteralLowering, &g_stringConstructorLowering, diff --git a/ets2panda/parser/ETSparserStatements.cpp b/ets2panda/parser/ETSparserStatements.cpp index e50e64f2c5bbe2db44035a075eaa239f1df5fb01..f19cef9385dc5e759baefcabeb57e4cefdf49ee3 100644 --- a/ets2panda/parser/ETSparserStatements.cpp +++ b/ets2panda/parser/ETSparserStatements.cpp @@ -342,9 +342,13 @@ ir::Statement *ETSParser::ParseClassStatement([[maybe_unused]] StatementParsingF ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags modFlags) { modFlags |= ParseClassModifiers(); - return ParseClassDeclaration(modifiers | ir::ClassDefinitionModifiers::ID_REQUIRED | - ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::LOCAL, - modFlags); + const auto &rangeClass = Lexer()->GetToken().Loc(); + LogError(diagnostic::ILLEGAL_START_STRUCT_CLASS, {"CLASS"}, rangeClass.start); + // Try to parse class and drop the result. + ParseClassDeclaration(modifiers | ir::ClassDefinitionModifiers::ID_REQUIRED | + ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::LOCAL, + modFlags); + return AllocBrokenStatement(rangeClass); } // NOLINTNEXTLINE(google-default-arguments) @@ -352,10 +356,11 @@ ir::Statement *ETSParser::ParseStructStatement([[maybe_unused]] StatementParsing ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags modFlags) { const auto &rangeStruct = Lexer()->GetToken().Loc(); - LogError(diagnostic::ILLEGAL_START_STRUCT, {}, rangeStruct.start); + LogError(diagnostic::ILLEGAL_START_STRUCT_CLASS, {"STRUCT"}, rangeStruct.start); + // Try to parse struct and drop the result. ParseClassDeclaration(modifiers | ir::ClassDefinitionModifiers::ID_REQUIRED | ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::LOCAL, - modFlags); // Try to parse struct and drop the result. + modFlags); return AllocBrokenStatement(rangeStruct); } diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index 9cfb10992b8bb3cc5456bfb32bd1c3b0a77c5f82..45b88fcc03bd5d1e8432f9d088e8aac04891aea2 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -289,7 +289,7 @@ ir::Statement *ParserImpl::ParsePotentialExpressionStatement(StatementParsingFla ir::Statement *ParserImpl::ParseStructStatement([[maybe_unused]] StatementParsingFlags flags, ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags modFlags) { - LogError(diagnostic::ILLEGAL_START_EXPRESSION); + LogError(diagnostic::ILLEGAL_START_STRUCT_CLASS, {"STRUCT"}); return ParseStructDeclaration(modifiers, modFlags); } diff --git a/ets2panda/test/ast/parser/ets/InvalidClasses.ets b/ets2panda/test/ast/parser/ets/InvalidClasses.ets index 9e535a9aadcd0c9e74f176ea0b0635f7b8db9055..5084f17fba70a2eb73de596c44680565ed44938c 100644 --- a/ets2panda/test/ast/parser/ets/InvalidClasses.ets +++ b/ets2panda/test/ast/parser/ets/InvalidClasses.ets @@ -112,6 +112,7 @@ interface I1 { /* @@? 58:25 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ /* @@? 58:25 Error SyntaxError: Unexpected token, expected ',' or ')'. */ /* @@? 58:25 Error SyntaxError: Unexpected token '}'. */ +/* @@? 61:5 Error SyntaxError: Illegal start of CLASS expression. */ /* @@? 62:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ /* @@? 66:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ /* @@? 66:18 Error SyntaxError: Private interface methods must have body. */ diff --git a/ets2panda/test/ast/parser/ets/InvalidStatements1.ets b/ets2panda/test/ast/parser/ets/InvalidStatements1.ets index d1736c1bb8bf7762f8911d53f8fb364e8e70cbb3..6243ebbacf651f81d09793376bcdf69d516fdf01 100644 --- a/ets2panda/test/ast/parser/ets/InvalidStatements1.ets +++ b/ets2panda/test/ast/parser/ets/InvalidStatements1.ets @@ -69,7 +69,8 @@ throw /* @@? 42:1 Error SyntaxError: A try statement should contain either finally clause or at least one catch clause. */ /* @@? 43:5 Error SyntaxError: Expected '{', got 'let'. */ /* @@? 45:9 Error SyntaxError: Unexpected token '{'. */ +/* @@? 47:1 Error SyntaxError: Illegal start of CLASS expression. */ /* @@? 48:5 Error SyntaxError: Unexpected token 'let'. */ /* @@? 52:1 Error SyntaxError: Illegal newline after throw. */ -/* @@? 76:1 Error SyntaxError: Expected '}', got 'eos'. */ -/* @@? 76:1 Error SyntaxError: Expected '}', got 'eos'. */ +/* @@? 77:1 Error SyntaxError: Expected '}', got 'eos'. */ +/* @@? 77:1 Error SyntaxError: Expected '}', got 'eos'. */ diff --git a/ets2panda/test/ast/parser/ets/class_variable_empty.ets b/ets2panda/test/ast/parser/ets/class_variable_empty.ets index aa702d4d0e01de724559f20930f285709885d74a..3b6947c97fca39f06a428cb3f8fdaa49f01cfc55 100644 --- a/ets2panda/test/ast/parser/ets/class_variable_empty.ets +++ b/ets2panda/test/ast/parser/ets/class_variable_empty.ets @@ -19,6 +19,10 @@ function main(): void { let a: A = new A; assertTrue(a != null) } - assertTrue(/* @@ label */a != null) + arktest.assertTrue(a != null) } -/* @@@ label Error TypeError: Unresolved reference a */ \ No newline at end of file + +/* @@? 18:5 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 19:12 Error TypeError: Cannot find type 'A'. */ +/* @@? 19:20 Error TypeError: Cannot find type 'A'. */ +/* @@? 22:3 Error TypeError: Unresolved reference arktest */ diff --git a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-private1.ets b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-private1.ets index 43fd173a70806341c2c6dba8e55ba85729f4fdb8..2e523713b2080beba4c86bf6aa4ad7eaf19494b3 100644 --- a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-private1.ets +++ b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-private1.ets @@ -17,7 +17,8 @@ function foo() { class LocalClass { - /* @@ label */private property : int; + private property : int; } } -/* @@@ label Error SyntaxError: Local class or interface declaration members can not have access modifies. */ +/* @@? 18:5 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 20:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ diff --git a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-private2.ets b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-private2.ets index 00c1422a83f5f616a574f7345426b4cc5922af6a..85dd9b2df4b39df25c45c2a629111e36230be502 100644 --- a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-private2.ets +++ b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-private2.ets @@ -17,8 +17,8 @@ function foo() { class LocalClass { - /* @@ label */private method() : void; + private method() : void; } } -/* @@@ label Error SyntaxError: Local class or interface declaration members can not have access modifies. */ -/* @@? 20:37 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 18:5 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 20:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ diff --git a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-protected1.ets b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-protected1.ets index 4091ddc869119bc3a1e8b189251605bea1daf63f..2e7a15b76051b8dd1bdc1babcbc6682660346392 100644 --- a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-protected1.ets +++ b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-protected1.ets @@ -17,7 +17,9 @@ function foo() { class LocalClass { - /* @@ label */protected property : int; + protected property : int; } } -/* @@@ label Error SyntaxError: Local class or interface declaration members can not have access modifies. */ + +/* @@? 18:5 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 20:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ diff --git a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-protected2.ets b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-protected2.ets index 3d9cee80d4b667ac1d9f2a21d7d344f12da85fa6..a320b25eb813baf3968b63b10c40eea7e582ce34 100644 --- a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-protected2.ets +++ b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-protected2.ets @@ -17,8 +17,9 @@ function foo() { class LocalClass { - /* @@ label */protected method() : void; + protected method() : void; } } -/* @@@ label Error SyntaxError: Local class or interface declaration members can not have access modifies. */ -/* @@? 20:39 Error TypeError: Only abstract or native methods can't have body. */ + +/* @@? 18:5 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 20:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ diff --git a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-public1.ets b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-public1.ets index 815ca264d023521421c5c7edcd8c10cab75d1bad..3b55135eb716a90729f5673ded62a3358b8da8ca 100644 --- a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-public1.ets +++ b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-public1.ets @@ -17,7 +17,8 @@ function foo() { class LocalClass { - /* @@ label */public property : int; + public property : int; } } -/* @@@ label Error SyntaxError: Local class or interface declaration members can not have access modifies. */ +/* @@? 18:5 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 20:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ diff --git a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-public2.ets b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-public2.ets index d04ccf89ed5efacf4becfa5ace585314df6a16da..5bf531cf9fa4fca5def0c8b9b03321b2ba0f860b 100644 --- a/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-public2.ets +++ b/ets2panda/test/ast/parser/ets/local-class-member-access-modifier-public2.ets @@ -17,8 +17,9 @@ function foo() { class LocalClass { - /* @@ label */public method() : void; + public method() : void; } } -/* @@@ label Error SyntaxError: Local class or interface declaration members can not have access modifies. */ -/* @@? 20:36 Error TypeError: Only abstract or native methods can't have body. */ + +/* @@? 18:5 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 20:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ diff --git a/ets2panda/test/ast/parser/ets/local_class_already_class.ets b/ets2panda/test/ast/parser/ets/local_class_already_class.ets index bd70f7cd3144d3c1295de2b86f1c3df46a4e9239..3bfff8e7d3288fbea0c3a9f4ec5a33df29683023 100644 --- a/ets2panda/test/ast/parser/ets/local_class_already_class.ets +++ b/ets2panda/test/ast/parser/ets/local_class_already_class.ets @@ -22,4 +22,5 @@ function bar(): void { } } -/* @@? 20:9 Error TypeError: Variable 'BC' has already been declared. */ +/* @@? 17:3 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 20:3 Error SyntaxError: Illegal start of CLASS expression. */ diff --git a/ets2panda/test/ast/parser/ets/local_class_already_interface.ets b/ets2panda/test/ast/parser/ets/local_class_already_interface.ets index d7deaccf10461ce84259c621e2f520c70c6bb36d..e9fea16e5276852d2e268c15cb1f2c51075ca1fc 100644 --- a/ets2panda/test/ast/parser/ets/local_class_already_interface.ets +++ b/ets2panda/test/ast/parser/ets/local_class_already_interface.ets @@ -22,4 +22,4 @@ function bar(): void { } } -/* @@? 20:9 Error TypeError: Variable 'BC' has already been declared. */ +/* @@? 20:3 Error SyntaxError: Illegal start of CLASS expression. */ diff --git a/ets2panda/test/ast/parser/ets/local_class_already_variable.ets b/ets2panda/test/ast/parser/ets/local_class_already_variable.ets index f336717b7414f212bb40a3fcdb2d165aa2f634d2..c784418b2ce2170e9025b84e7b9455a1616f46cb 100644 --- a/ets2panda/test/ast/parser/ets/local_class_already_variable.ets +++ b/ets2panda/test/ast/parser/ets/local_class_already_variable.ets @@ -20,4 +20,4 @@ function bar(): void { } } -/* @@? 18:9 Error TypeError: Variable 'BC' has already been declared. */ +/* @@? 18:3 Error SyntaxError: Illegal start of CLASS expression. */ diff --git a/ets2panda/test/ast/parser/ets/local_class_in_classfunction.ets b/ets2panda/test/ast/parser/ets/local_class_in_classfunction.ets index c81cd8a8b239834ba78f629234d4c72f04608d0f..7ae5c158dfa2c47475619c403868faad995102e6 100644 --- a/ets2panda/test/ast/parser/ets/local_class_in_classfunction.ets +++ b/ets2panda/test/ast/parser/ets/local_class_in_classfunction.ets @@ -49,13 +49,13 @@ class A_class{ } } -/* @@? 21:24 Error TypeError: Property 'localfield' of enclosing class 'A_class' is not allowed to be captured from the local class 'LocalClass' */ -/* @@? 21:24 Error TypeError: Property 'localfield' must be accessed through 'this' */ -/* @@? 26:29 Error TypeError: Property 'localfield' does not exist on type 'FinalLocalClass' */ -/* @@? 30:41 Error TypeError: Cannot inherit with 'final' modifier. */ -/* @@? 31:53 Error TypeError: Cannot use both 'final' and 'abstract' modifiers. */ -/* @@? 36:37 Error TypeError: AbstractLocalClass2 is abstract therefore cannot be instantiated. */ -/* @@? 39:13 Error TypeError: Invalid method modifier(s): an abstract method can't have private, override, static, final or native modifier. */ -/* @@? 40:31 Error TypeError: Native, Abstract and Declare methods cannot have body. */ -/* @@? 43:65 Error TypeError: FinalLocalClass2 is not abstract and does not override abstract method method3(): void in FinalLocalClass2 */ -/* @@? 45:13 Error TypeError: Non abstract class has abstract method. */ \ No newline at end of file +/* @@? 18:18 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 19:9 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 24:15 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 30:9 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 31:24 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 33:18 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 36:15 Error TypeError: Cannot find type 'AbstractLocalClass2'. */ +/* @@? 36:41 Error TypeError: Cannot find type 'AbstractLocalClass2'. */ +/* @@? 38:18 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 43:15 Error SyntaxError: Illegal start of CLASS expression. */ diff --git a/ets2panda/test/ast/parser/ets/local_interface_already_class.ets b/ets2panda/test/ast/parser/ets/local_interface_already_class.ets index 30b81abff89c8d5f9287a5180cbc9228b4d679bb..a1458dd7714a8573a654f57cb1afe10d621ea107 100644 --- a/ets2panda/test/ast/parser/ets/local_interface_already_class.ets +++ b/ets2panda/test/ast/parser/ets/local_interface_already_class.ets @@ -22,4 +22,4 @@ function bar(): void { } } -/* @@? 20:3 Error TypeError: Variable 'BC' has already been declared. */ +/* @@? 17:3 Error SyntaxError: Illegal start of CLASS expression. */ diff --git a/ets2panda/test/ast/parser/ets/unexpected_token_63.ets b/ets2panda/test/ast/parser/ets/unexpected_token_63.ets index 833cf39392af4e1f38e1c0aec5594b1c876f67c9..1700c77c638e2f143b2cd0a681f0a92193a9baba 100644 --- a/ets2panda/test/ast/parser/ets/unexpected_token_63.ets +++ b/ets2panda/test/ast/parser/ets/unexpected_token_63.ets @@ -53,6 +53,7 @@ class A { /* @@? 23:21 Error SyntaxError: Unexpected token 'final'. */ /* @@? 23:21 Error SyntaxError: Unexpected token, expected ',' or ')'. */ /* @@? 23:21 Error SyntaxError: Unexpected token 'final'. */ +/* @@? 23:26 Error SyntaxError: Illegal start of CLASS expression. */ /* @@? 23:39 Error SyntaxError: Expected '{', got ')'. */ /* @@? 26:2 Error SyntaxError: Unexpected token '}'. */ /* @@? 27:1 Error SyntaxError: Unexpected token '}'. */ diff --git a/ets2panda/test/parser/ets/local-class-expected.txt b/ets2panda/test/parser/ets/local-class-expected.txt deleted file mode 100644 index 8b51c20764435b9364c1b05cfd81cd26c986c368..0000000000000000000000000000000000000000 --- a/ets2panda/test/parser/ets/local-class-expected.txt +++ /dev/null @@ -1,481 +0,0 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "ETSGLOBAL", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "local-class.ets" - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "_$init$_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "kind": "method", - "accessibility": "public", - "static": true, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "_$init$_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "local-class.ets" - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 10, - "program": "local-class.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "local-class.ets" - } - } - }, - "kind": "method", - "accessibility": "public", - "static": true, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 10, - "program": "local-class.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "local-class.ets" - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "returnType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 16, - "column": 19, - "program": "local-class.ets" - }, - "end": { - "line": 16, - "column": 22, - "program": "local-class.ets" - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "LocalClass", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 11, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 21, - "program": "local-class.ets" - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "kind": "constructor", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 23, - "program": "local-class.ets" - }, - "end": { - "line": 18, - "column": 23, - "program": "local-class.ets" - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - } - ], - "loc": { - "start": { - "line": 18, - "column": 22, - "program": "local-class.ets" - }, - "end": { - "line": 19, - "column": 11, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 5, - "program": "local-class.ets" - }, - "end": { - "line": 19, - "column": 11, - "program": "local-class.ets" - } - } - }, - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 19, - "column": 12, - "program": "local-class.ets" - }, - "end": { - "line": 19, - "column": 13, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 5, - "program": "local-class.ets" - }, - "end": { - "line": 19, - "column": 14, - "program": "local-class.ets" - } - } - } - ], - "loc": { - "start": { - "line": 17, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 10, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 10, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "local-class.ets" - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "local-class.ets" - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "local-class.ets" - }, - "end": { - "line": 20, - "column": 2, - "program": "local-class.ets" - } - } -} diff --git a/ets2panda/test/parser/ets/local-class.ets b/ets2panda/test/parser/ets/local-class.ets deleted file mode 100644 index 94e03361a4137d274d079cf3232dc94c77aa1efd..0000000000000000000000000000000000000000 --- a/ets2panda/test/parser/ets/local-class.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2024-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() : int -{ - class LocalClass { } - return 0; -} \ No newline at end of file diff --git a/ets2panda/test/parser/ets/localClassIsPermitted-expected.txt b/ets2panda/test/parser/ets/localClassIsPermitted-expected.txt deleted file mode 100644 index 0995504c47e516997f6c36a44cf850c701fa0031..0000000000000000000000000000000000000000 --- a/ets2panda/test/parser/ets/localClassIsPermitted-expected.txt +++ /dev/null @@ -1,672 +0,0 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "Klass", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 7, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 16, - "column": 12, - "program": "localClassIsPermitted.ets" - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "ClassStaticBlock", - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "generator": false, - "async": false, - "expression": true, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "Local", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 15, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 18, - "column": 20, - "program": "localClassIsPermitted.ets" - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - } - } - }, - "kind": "constructor", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 18, - "column": 22, - "program": "localClassIsPermitted.ets" - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - } - ], - "loc": { - "start": { - "line": 18, - "column": 21, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 21, - "column": 6, - "program": "localClassIsPermitted.ets" - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 9, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 21, - "column": 6, - "program": "localClassIsPermitted.ets" - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 5, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 21, - "column": 6, - "program": "localClassIsPermitted.ets" - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - } - } - }, - "kind": "constructor", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 16, - "column": 14, - "program": "localClassIsPermitted.ets" - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 13, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 23, - "column": 1, - "program": "localClassIsPermitted.ets" - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 1, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 23, - "column": 1, - "program": "localClassIsPermitted.ets" - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "ETSGLOBAL", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "kind": "method", - "accessibility": "public", - "static": true, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "_$init$_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "kind": "method", - "accessibility": "public", - "static": true, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "_$init$_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": null - }, - "end": { - "line": 1, - "column": 1, - "program": null - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1, - "program": "localClassIsPermitted.ets" - }, - "end": { - "line": 23, - "column": 1, - "program": "localClassIsPermitted.ets" - } - } -} diff --git a/ets2panda/test/parser/ets/localClassIsPermitted.ets b/ets2panda/test/parser/ets/localClassIsPermitted.ets deleted file mode 100644 index 85aa2cd787a3804b6d0e85bba723c87401c93965..0000000000000000000000000000000000000000 --- a/ets2panda/test/parser/ets/localClassIsPermitted.ets +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024-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 Klass { - static { - class Local { - - } - } -} diff --git a/ets2panda/test/runtime/ets/InterfaceInBlock.ets b/ets2panda/test/runtime/ets/InterfaceInBlock.ets deleted file mode 100644 index 0674863ac13521b61981c34f706003060699c344..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/InterfaceInBlock.ets +++ /dev/null @@ -1,31 +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. - */ - -{ - interface I - { - foo(): int; - } - - class C implements I - { - foo(): int - { - return 1; - } - } - - assertEQ(new C().foo(), 1); -} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/lambdaWithLocalClassAccess.ets b/ets2panda/test/runtime/ets/lambdaWithLocalClassAccess.ets deleted file mode 100644 index 6f004b09483914a19b12101d62964e0baac71f7c..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/lambdaWithLocalClassAccess.ets +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2024-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 f() { - class C { - x: boolean = true - } - let lam = (c: C): boolean => { return c.x } - assertTrue(lam(new C())) -} - -function main() { - f() -} diff --git a/ets2panda/test/runtime/ets/lambda_with_default.ets b/ets2panda/test/runtime/ets/lambda_with_default.ets deleted file mode 100644 index 85e5cf14dd61752a5d4634e502557813364ea232..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/lambda_with_default.ets +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2024-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() { - ()=> { - class A { - foo(x :String ="aa"){ - return x; - } - } - } - assertTrue(true) -} diff --git a/ets2panda/test/runtime/ets/local-class-capture-boxing.ets b/ets2panda/test/runtime/ets/local-class-capture-boxing.ets deleted file mode 100644 index 0ddecafe02f2695aca1947efa51947ec1365eaab..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-capture-boxing.ets +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2021-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 UserClassType -{ - v : int = 0; - constructor (p : int) - { - this.v = p; - } - - override toString() : string { - return Int.valueOf(this.v).toString(); - } -} - -enum UserEnumType -{ - Red, - Green, - Blue -}; - -let g_array : int [] = [1,2,3]; -let g_array2 : int [] = [11,12,13]; -let g_Array : Array = new Array(new Int(4), new Int(5), new Int(6)); -let g_Array2 : Array = new Array(new Int(14), new Int(15), new Int(16)); -let g_Object : Object = new Object(); -let g_Object2 : Object = new Object(); -let g_Class : UserClassType = new UserClassType(25); -let g_Class2 : UserClassType = new UserClassType(250); - - - -class GlobalClass -{ - static s_field : int = 13; - field : int = 14; - - static s_method_boxing_local_class() { - // predefined value types - let l_number : number = 1; - let l_byte : byte = 2; - let l_short : short = 3; - let l_int : int = 4; - let l_long : long = 5; - let l_float : float = 6.0; - let l_double : double = 7.0; - let l_boolean : boolean = false; - let l_char : char = c'x'; - - // user defined value types - let l_enum : UserEnumType = UserEnumType.Red; - - // predefined reference types - let l_Number : Number = new Number(11); - let l_Byte : Byte = new Byte(12 as byte); - let l_Short : Short = new Short(13 as short); - let l_Int : Int = new Int(14 as int); - let l_Long : Long = new Long(15 as long); - let l_Float : Float = new Float(16.0); - let l_Double : Double = new Double(17.0); - let l_Boolean: Boolean = new Boolean(false); - let l_Char : Char = new Char(c'X'); - - let l_string : string = "something"; - let l_String : String = new String("Something"); - let l_array : int [] = g_array; - let l_Array : Array = g_Array; - //let l_bigint : bigint = 20n; - //let l_BigInt : BigInt = new BigInt(21n); - let l_Object : Object = g_Object; - - // user defined reference types - let l_Class : UserClassType = g_Class; - - class LocalClassBoxing - { - local_field : int = 1000; - static local_s_field : int = 2000; - - static local_s_method(lp : int) : void - { - assertEQ(lp, 300) - assertEQ(LocalClassBoxing.local_s_field, 2000) - - LocalClassBoxing.local_s_field = 5000; - assertEQ(LocalClassBoxing.local_s_field, 5000) - } - - local_method(lp : int) : void - { - // Parameter - assertEQ(lp, 400) - // Local class object field - assertEQ(this.local_field, 1000) - // Local class static field - assertEQ(LocalClassBoxing.local_s_field, 5000) - // Outer class static field - assertEQ(GlobalClass.s_field, 13) - // Predefined value types - assertEQ(l_number, 1) - assertEQ(l_byte, 2) - assertEQ(l_short, 3) - assertEQ(l_int, 4) - assertEQ(l_long, 5) - assertEQ(l_float, 6) - assertEQ(l_double, 7) - assertEQ(l_boolean, false) - assertEQ(l_char, c'x') - // User defined value type - assertEQ(l_enum, UserEnumType.Red) - // Predefined reference types - assertEQ(l_Number, Number.valueOf(11)) - assertEQ(l_Byte, Byte.valueOf(12 as byte)) - assertEQ(l_Short, Short.valueOf(13 as short)) - assertEQ(l_Int, Int.valueOf(14 as int)) - assertEQ(l_Long, Long.valueOf(15 as long)) - assertEQ(l_Float, Float.valueOf(16 as float)) - assertEQ(l_Double, Double.valueOf(17 as double)) - assertEQ(l_Boolean, Boolean.valueOf(false)) - assertEQ(l_Char, Char.valueOf(c'X')) - assertEQ(l_string, "something") - assertEQ(l_String, "Something") - // assertEQ(l_array, g_array) - // assertEQ(l_Array, g_Array) - assertEQ(l_Object, g_Object) - assertEQ(l_Class, g_Class) - - this.local_field = 1100; - LocalClassBoxing.local_s_field = 5100; - - l_number = 101; - l_byte = 102; - l_short = 103; - l_int = 104; - l_long = 105; - l_float = 106.0; - l_double = 107.0; - l_boolean = true; - l_char = c'y'; - //l_enum = UserEnumType.Green; - - l_Number = new Number(111); - l_Byte = new Byte(112 as byte); - l_Short = new Short(113 as short); - l_Int = new Int(114 as int); - l_Long = new Long(115 as long); - l_Float = new Float(116.0); - l_Double = new Double(117.0); - l_Boolean = new Boolean(true); - l_Char = new Char(c'Y'); - - l_string = "something new"; - l_String = new String("Something new"); - l_array = g_array2; - l_Array = g_Array2; - l_Object = g_Object2; - l_Class = g_Class2; - } - }; - LocalClassBoxing.local_s_field = 2000; // due to the jit loop - LocalClassBoxing.local_s_method(300); - - let lcb = new LocalClassBoxing(); - lcb.local_method(400); - - assertEQ(lcb.local_field, 1100) - assertEQ(LocalClassBoxing.local_s_field, 5100) - assertEQ(l_number, 101) - assertEQ(l_byte, 102) - assertEQ(l_short, 103) - assertEQ(l_int, 104) - assertEQ(l_long, 105) - assertEQ(l_float, 106) - assertEQ(l_double, 107) - assertEQ(l_boolean, true) - assertEQ(l_char, c'y') - - //assertEQ(l_enum, UserEnumType.Green) - - // Predefined reference types - assertEQ(l_Number, Number.valueOf(111)) - assertEQ(l_Byte, Byte.valueOf(112 as byte)) - assertEQ(l_Short, Short.valueOf(113 as short)) - assertEQ(l_Int, Int.valueOf(114 as int)) - assertEQ(l_Long, Long.valueOf(115 as long)) - assertEQ(l_Float, Float.valueOf(116 as float)) - assertEQ(l_Double, Double.valueOf(117 as double)) - assertEQ(l_Boolean, Boolean.valueOf(true)) - assertEQ(l_Char, Char.valueOf(c'Y')) - assertEQ(l_string, "something new") - assertEQ(l_String, "Something new") - //assertEQ(l_array, g_array2) - //assertEQ(l_Array, g_Array2) - assertEQ(l_Object, g_Object2) - assertEQ(l_Class, g_Class2) - } -} - - -function main() : int -{ - GlobalClass.s_method_boxing_local_class(); - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-capture-not-boxing.ets b/ets2panda/test/runtime/ets/local-class-capture-not-boxing.ets deleted file mode 100644 index b22d5bb64c4de397121cf8e3990ab6cf8d21cef2..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-capture-not-boxing.ets +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2021-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 UserClassType -{ - v : int = 0; - constructor (p : int) - { - this.v = p; - } - - override toString() : string { - return Int.valueOf(this.v).toString(); - } -} - -enum UserEnumType -{ - Red, - Green, - Blue -}; - -let g_array : int [] = [1,2,3]; -let g_array2 : int [] = [11,12,13]; -let g_Array : Array = new Array(new Int(4), new Int(5), new Int(6)); -let g_Array2 : Array = new Array(new Int(14), new Int(15), new Int(16)); -let g_Object : Object = new Object(); -let g_Object2 : Object = new Object(); -let g_Class : UserClassType = new UserClassType(25); -let g_Class2 : UserClassType = new UserClassType(250); - - - -class GlobalClass -{ - static s_field : int = 13; - field : int = 14; - - static s_method_not_boxing_local_class() { - // predefined value types - let l_number : number = 1; - let l_byte : byte = 2; - let l_short : short = 3; - let l_int : int = 4; - let l_long : long = 5; - let l_float : float = 6.0; - let l_double : double = 7.0; - let l_boolean : boolean = false; - let l_char : char = c'x'; - - // user defined value types - let l_enum : UserEnumType = UserEnumType.Red; - - // predefined reference types - let l_Number : Number = new Number(11); - let l_Byte : Byte = new Byte(12 as byte); - let l_Short : Short = new Short(13 as short); - let l_Int : Int = new Int(14 as int); - let l_Long : Long = new Long(15 as long); - let l_Float : Float = new Float(16.0); - let l_Double : Double = new Double(17.0); - let l_Boolean: Boolean = new Boolean(false); - let l_Char : Char = new Char(c'X'); - - let l_string : string = "something"; - let l_String : String = new String("Something"); - let l_array : int [] = g_array; - let l_Array : Array = g_Array; - //let l_bigint : bigint = 20n; - //let l_BigInt : BigInt = new BigInt(21n); - let l_Object : Object = g_Object; - - // user defined reference types - let l_Class : UserClassType = g_Class; - - class LocalClassNotBoxing - { - local_field : int = 100; - static local_s_field : int = 200; - - static local_s_method(lp : int) : void - { - assertEQ(lp, 30) - assertEQ(LocalClassNotBoxing.local_s_field, 200) - } - - local_method(lp : int) : void - { - // Parameter - assertEQ(lp, 40) - // Local class object field - assertEQ(this.local_field, 100) - // Local class static field - assertEQ(LocalClassNotBoxing.local_s_field, 200) - // Predefined value types - assertEQ(l_number, 1) - assertEQ(l_byte, 2) - assertEQ(l_short, 3) - assertEQ(l_int, 4) - assertEQ(l_long, 5) - assertEQ(l_float, 6) - assertEQ(l_double, 7) - assertEQ(l_boolean, false) - assertEQ(l_char, c'x') - // User defined value type - assertEQ(l_enum, UserEnumType.Red) - // Predefined reference types - assertEQ(l_Number, Number.valueOf(11)) - assertEQ(l_Byte, Byte.valueOf(12 as byte)) - assertEQ(l_Short, Short.valueOf(13 as short)) - assertEQ(l_Int, Int.valueOf(14 as int)) - assertEQ(l_Long, Long.valueOf(15 as long)) - assertEQ(l_Float, Float.valueOf(16 as float)) - assertEQ(l_Double, Double.valueOf(17 as double)) - assertEQ(l_Boolean, Boolean.valueOf(false)) - assertEQ(l_Char, Char.valueOf(c'X')) - assertEQ(l_string, "something") - assertEQ(l_String, "Something") - assertEQ(l_array, g_array) - assertEQ(l_Array, g_Array) - assertEQ(l_Object, g_Object) - assertEQ(l_Class, g_Class) - } - }; - - LocalClassNotBoxing.local_s_method(30); - - let lc = new LocalClassNotBoxing(); - lc.local_method(40); - } -} - - -function main() : int -{ - GlobalClass.s_method_not_boxing_local_class(); - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-capture-parameter.ets b/ets2panda/test/runtime/ets/local-class-capture-parameter.ets deleted file mode 100644 index c931bf4fdab2fa29128f353f85503f572572369b..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-capture-parameter.ets +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021-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 GlobalClass -{ - static capture_param_method(param : int) - { - class LocalClass - { - method() - { - assertEQ(param, 1) - } - } - - let lc = new LocalClass(); - lc.method() - } -} - -function main() : int -{ - GlobalClass.capture_param_method(1); - - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-in-local-class.ets b/ets2panda/test/runtime/ets/local-class-in-local-class.ets deleted file mode 100644 index 680ea18e4bf80cfb02cd0b27a0f2681c3ce2c2a8..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-in-local-class.ets +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021-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() : int -{ - let l_int = 0; - - class LocalClassLevel1 - { - m_int1 = 11; - - method1() - { - let l_int2 = 12; - assertEQ(this.m_int1, 11) - assertEQ(l_int, 0) - l_int = 1; - - class LocalClassLevel2 - { - m_int2 : int = 22; - - method2() { - assertEQ(this.m_int2, 22) - assertEQ(l_int2, 12) - l_int2 = 13; - } - } - - let lcl2 = new LocalClassLevel2(); - lcl2.method2(); - assertEQ(l_int2, 13) - } - } - - let lcl1 = new LocalClassLevel1(); - lcl1.method1(); - assertEQ(l_int, 1) - - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-mixed-capture.ets b/ets2panda/test/runtime/ets/local-class-mixed-capture.ets deleted file mode 100644 index 916b84c4d2c659df8bfff2d6b2314b8745ac6d8a..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-mixed-capture.ets +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021-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() : int -{ - // Since the BoxingLocalClass modifies the 'i' it has to be boxed and use it as a boxed - // variable in the NotBoxingLocalClass too - let i : int = 1; - - class NotBoxingLocalClass - { - local_method() - { - assertEQ(i, 1) - } - } - - class BoxingLocalClass - { - local_method() - { - assertEQ(i, 1) - i = 2; - } - } - - let nblc = new NotBoxingLocalClass(); - nblc.local_method(); - - let blc = new BoxingLocalClass(); - blc.local_method(); - assertEQ(i, 2) - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-modify-captured-parameter.ets b/ets2panda/test/runtime/ets/local-class-modify-captured-parameter.ets deleted file mode 100644 index c217536ffd8227251751def07f819994cea58b40..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-modify-captured-parameter.ets +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021-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 GlobalClass -{ - static capture_param_method(param : int) - { - class LocalClass - { - method() - { - assertEQ(param, 1) - param = 3; - } - } - - let lc = new LocalClass(); - lc.method() - assertEQ(param, 3) - } -} - -function main() : int -{ - GlobalClass.capture_param_method(1); - - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-standard-example1.ets b/ets2panda/test/runtime/ets/local-class-standard-example1.ets deleted file mode 100644 index 99429c2fcc8cda2cfe2b38b2ea604c205c794144..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-standard-example1.ets +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2021-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 foo (parameter: number) { - let local: string = "function local"; - interface LocalInterface { // Local interface in a top-level function - method (): void; // It has a method - field: string; // and a property - } - class LocalClass implements LocalInterface { // Class implements interface - // Local class in a top-level function - override method () { - console.log ("Instance field = " + this.field + " par = " + parameter + " loc = " + local ) - assertEQ(this.field, "`instance field value`") - assertEQ(parameter, 42) - assertEQ(local, "function local") - } - field: string = "`instance field value`" - static s_method () { - console.log ("Static field = " + LocalClass.s_field) - assertEQ(LocalClass.s_field, "`class/static field value`") - - } - static s_field: string = "`class/static field value`" - } - - let lc: LocalInterface = new LocalClass(); - // Both local types can be freely used in the top-level function scope - lc.method() - LocalClass.s_method() -} - -function main() : int -{ - foo(42); - return 0; -} diff --git a/ets2panda/test/runtime/ets/local-class-standard-example2.ets b/ets2panda/test/runtime/ets/local-class-standard-example2.ets deleted file mode 100644 index 313b2e96edc551ead003990d9f42d22ae9c15d3a..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local-class-standard-example2.ets +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2021-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 { - field: number = 1234 // Not visible for the local class - method (parameter: number) { - let local: string = "instance local" - - interface LocalInterface { - method (): void - field: string - } - - class LocalClass implements LocalInterface { - override method () { - console.log ("Instance field = " + this.field + " par = " + parameter + " loc = " + local ) - assertEQ(this.field, "`instance method instance field value`") - assertEQ(parameter, 42) - assertEQ(local, "instance local") - - } - field: string = "`instance method instance field value`" - static s_method () { - console.log ("Static field = " + LocalClass.s_field) - assertEQ(LocalClass.s_field, "`instance method class/static field value`") - } - static s_field: string = "`instance method class/static field value`" - } - - let lc: LocalInterface = new LocalClass - lc.method() - LocalClass.s_method() - } - - static s_method (parameter: number) { - let local: string = "class/static local" - interface LocalInterface { - method (): void - field: string - } - - class LocalClass implements LocalInterface { - override method () { - console.log ("Instance field = " + this.field + " par = " + parameter + " loc = " + local) - assertEQ(this.field, "`static method instance field value`") - assertEQ(parameter, 72) - assertEQ(local, "class/static local") - } - field: string = "`static method instance field value`" - static s_method () { - console.log ("Static field = " + LocalClass.s_field) - assertEQ(LocalClass.s_field, "`static method class/static field value`") - } - static s_field: string = "`static method class/static field value`" - } - let lc: LocalInterface = new LocalClass - lc.method() - LocalClass.s_method() - } -} - -function main() : int -{ - A_class.s_method(72); - - let a = new A_class(); - a.method(42) - - return 0; -} diff --git a/ets2panda/test/runtime/ets/local_class_in_classfunction.ets b/ets2panda/test/runtime/ets/local_class_in_classfunction.ets deleted file mode 100644 index 08bd662e7b238eb94ca7a12d98988c60be40569f..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local_class_in_classfunction.ets +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2024-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{ - foo(){ - let localfield:string = "localstring"; - abstract class AbstractLocalClass{ - field1:int = 100; - } - class LocalClass extends AbstractLocalClass{ - field2:int = 200; - static staticfield = 300; - method1(){ - assertEQ(this.field1, 100) - assertEQ(this.field2, 200) - assertEQ(localfield, "localstring") - } - static method2(){ - assertEQ(LocalClass.staticfield, 300) - } - } - final class FinalLocalClass{ - field1:int = 100; - static staticfield = 300; - method1(){ - assertEQ(this.field1, 100) - assertEQ(localfield, "localstring") - } - static method2(){ - assertEQ(LocalClass.staticfield, 300) - } - } - - let x:AbstractLocalClass = new LocalClass(); - assertEQ(x.field1, 100) - assertEQ(x.field2, 200) - assertEQ(LocalClass.staticfield, 300) - x.method1(); - LocalClass.method2(); - - let x2:FinalLocalClass = new FinalLocalClass(); - assertEQ(x2.field1, 100) - assertEQ(FinalLocalClass.staticfield, 300) - x2.method1() - FinalLocalClass.method2(); - } -} - -function main():void -{ - let x3:A_class = new A_class; - x3.foo(); -} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/local_class_in_function.ets b/ets2panda/test/runtime/ets/local_class_in_function.ets deleted file mode 100644 index 7457a257ef58497f3419de39143d385a34d86d04..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/local_class_in_function.ets +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2024-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():void -{ - let localint:int = 200; - - abstract class AbstractLocalClass{ - field1:int = 10; - } - - class LocalClass extends AbstractLocalClass{ - field2:int = 20; - static staticfield = 30; - method1(){ - assertEQ(this.field1, 10) - assertEQ(this.field2, 20) - assertEQ(localint, 200) - } - static method2(){ - assertEQ(LocalClass.staticfield, 30) - } - } - - final class FinalLocalClass{ - field1:int = 10; - static staticfield = 30; - method1(){ - assertEQ(this.field1, 10) - assertEQ(localint, 200) - } - static method2(){ - assertEQ(FinalLocalClass.staticfield, 30) - } - } - - let x:AbstractLocalClass = new LocalClass(); - assertEQ(x.field1, 10) - assertEQ(x.field2, 20) - assertEQ(LocalClass.staticfield, 30) - x.method1(); - LocalClass.method2(); - - let x2:FinalLocalClass = new FinalLocalClass(); - assertEQ(x2.field1, 10) - assertEQ(FinalLocalClass.staticfield, 30) - x2.method1() - FinalLocalClass.method2(); -} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/statement_after_local_class.ets b/ets2panda/test/runtime/ets/statement_after_local_class.ets deleted file mode 100644 index 6b000813b015b274e3349a7932f7262794fd96c0..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/statement_after_local_class.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2024-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(): void { - class MyClass { - constructor() { - } - - foo(): number { - return 1.0 - } - } - - let m = new MyClass() - - assertEQ(m.foo(), 1.0) -} diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 465347e084fe629eda60dd36511d7b93fbb3b906..0302ac682b6cd8f4fcf4b6bb58d5cdbddf03b7e8 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -168,9 +168,9 @@ syntax: id: 39 message: "A try statement should contain either finally clause or at least one catch clause." -- name: ILLEGAL_START_STRUCT +- name: ILLEGAL_START_STRUCT_CLASS id: 40 - message: "Illegal start of STRUCT expression." + message: "Illegal start of {} expression." - name: ONLY_EXPORT_CLASS_OR_INTERFACE id: 41