From 6153cd754acf73f817c26abb9a16a89a7a21db6d Mon Sep 17 00:00:00 2001 From: aleksisch Date: Wed, 14 Feb 2024 23:13:26 +0300 Subject: [PATCH 1/2] make functional object true field instead of method Signed-off-by: aleksisch --- ets2panda/checker/ets/helpers.cpp | 13 +----- ets2panda/checker/ets/object.cpp | 25 +----------- ets2panda/checker/types/ets/etsObjectType.cpp | 40 +++++-------------- ets2panda/checker/types/ets/etsObjectType.h | 1 + ets2panda/ir/expressions/memberExpression.cpp | 12 ++++-- .../ets/identifierReference12-expected.txt | 2 +- ...dIndirectInheritanceFromClass-expected.txt | 2 +- ...irectInheritanceFromInterface-expected.txt | 2 +- .../ets/invalidInheritance3-expected.txt | 1 - .../invalidInheritanceFromClass-expected.txt | 2 +- ...validInheritanceFromInterface-expected.txt | 2 +- ets2panda/varbinder/variableFlags.h | 31 +++++++------- 12 files changed, 41 insertions(+), 92 deletions(-) diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index ac3b09f01e..72b9c72aaf 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2038,18 +2038,7 @@ std::string ETSChecker::GetStringFromLiteral(ir::Expression *caseTest) const bool ETSChecker::IsSameDeclarationType(varbinder::LocalVariable *target, varbinder::LocalVariable *compare) { - if (target->Declaration()->Type() != compare->Declaration()->Type()) { - return false; - } - - if ((target->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE) && - !compare->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE)) || - (!target->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE) && - compare->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE))) { - return false; - } - - return true; + return target->Declaration()->Type() == compare->Declaration()->Type(); } void ETSChecker::AddBoxingFlagToPrimitiveType(TypeRelation *relation, Type *target) diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 4e3c59a4b5..7dd15d730f 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -382,17 +382,6 @@ static void ResolveDeclaredFieldsOfObject(ETSChecker *checker, const ETSObjectTy auto *classProp = it->Declaration()->Node()->AsClassProperty(); it->AddFlag(checker->GetAccessFlagFromNode(classProp)); type->AddProperty(it->AsLocalVariable()); - - if (classProp->TypeAnnotation() != nullptr && classProp->TypeAnnotation()->IsETSFunctionType()) { - type->AddProperty(it->AsLocalVariable()); - it->AddFlag(varbinder::VariableFlags::METHOD_REFERENCE); - } else if (classProp->TypeAnnotation() != nullptr && classProp->TypeAnnotation()->IsETSTypeReference()) { - bool hasFunctionType = checker->HasETSFunctionType(classProp->TypeAnnotation()); - if (hasFunctionType) { - type->AddProperty(it->AsLocalVariable()); - it->AddFlag(varbinder::VariableFlags::METHOD_REFERENCE); - } - } } for (auto &[_, it] : scope->StaticFieldScope()->Bindings()) { @@ -401,17 +390,6 @@ static void ResolveDeclaredFieldsOfObject(ETSChecker *checker, const ETSObjectTy auto *classProp = it->Declaration()->Node()->AsClassProperty(); it->AddFlag(checker->GetAccessFlagFromNode(classProp)); type->AddProperty(it->AsLocalVariable()); - - if (classProp->TypeAnnotation() != nullptr && classProp->TypeAnnotation()->IsETSFunctionType()) { - type->AddProperty(it->AsLocalVariable()); - it->AddFlag(varbinder::VariableFlags::METHOD_REFERENCE); - } else if (classProp->TypeAnnotation() != nullptr && classProp->TypeAnnotation()->IsETSTypeReference()) { - bool hasFunctionType = checker->HasETSFunctionType(classProp->TypeAnnotation()); - if (hasFunctionType) { - type->AddProperty(it->AsLocalVariable()); - it->AddFlag(varbinder::VariableFlags::METHOD_REFERENCE); - } - } } } @@ -1215,7 +1193,8 @@ varbinder::Variable *ETSChecker::ResolveInstanceExtension(const ir::MemberExpres PropertySearchFlags ETSChecker::GetInitialSearchFlags(const ir::MemberExpression *const memberExpr) { - constexpr auto FUNCTIONAL_FLAGS = PropertySearchFlags::SEARCH_METHOD | PropertySearchFlags::IS_FUNCTIONAL; + constexpr auto FUNCTIONAL_FLAGS = + PropertySearchFlags::SEARCH_METHOD | PropertySearchFlags::IS_FUNCTIONAL | PropertySearchFlags::SEARCH_FIELD; constexpr auto GETTER_FLAGS = PropertySearchFlags::SEARCH_METHOD | PropertySearchFlags::IS_GETTER; constexpr auto SETTER_FLAGS = PropertySearchFlags::SEARCH_METHOD | PropertySearchFlags::IS_SETTER; diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 8368bd2f7e..4bc113218a 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -41,7 +41,8 @@ void ETSObjectType::Iterate(const PropertyTraverser &cb) const } } -varbinder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &name, PropertySearchFlags flags) const +varbinder::LocalVariable *ETSObjectType::SearchFieldsDecls(const util::StringView &name, + PropertySearchFlags flags) const { varbinder::LocalVariable *res {}; if ((flags & PropertySearchFlags::SEARCH_INSTANCE_FIELD) != 0) { @@ -59,13 +60,13 @@ varbinder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &nam if (res == nullptr && ((flags & PropertySearchFlags::SEARCH_STATIC_DECL) != 0)) { res = GetOwnProperty(name); } + return res; +} +varbinder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &name, PropertySearchFlags flags) const +{ + varbinder::LocalVariable *res = SearchFieldsDecls(name, flags); if (res == nullptr && (flags & PropertySearchFlags::SEARCH_METHOD) != 0) { - res = GetOwnProperty(name); - if (res != nullptr && res->TsType() != nullptr && res->TsType()->IsETSDynamicType()) { - return res; - } - res = nullptr; if ((flags & PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION) != 0) { if ((flags & PropertySearchFlags::SEARCH_INSTANCE_METHOD) != 0) { res = GetOwnProperty(name); @@ -79,15 +80,7 @@ varbinder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &nam } } - if ((flags & (PropertySearchFlags::SEARCH_IN_INTERFACES | PropertySearchFlags::SEARCH_IN_BASE)) == 0) { - return res; - } - - if (res != nullptr) { - return res; - } - - if ((flags & PropertySearchFlags::SEARCH_IN_INTERFACES) != 0) { + if (res == nullptr && (flags & PropertySearchFlags::SEARCH_IN_INTERFACES) != 0) { for (auto *interface : interfaces_) { res = interface->GetProperty(name, flags); if (res != nullptr) { @@ -96,7 +89,7 @@ varbinder::LocalVariable *ETSObjectType::GetProperty(const util::StringView &nam } } - if (superType_ != nullptr && ((flags & PropertySearchFlags::SEARCH_IN_BASE) != 0)) { + if (res == nullptr && superType_ != nullptr && ((flags & PropertySearchFlags::SEARCH_IN_BASE) != 0)) { res = superType_->GetProperty(name, flags); } @@ -146,18 +139,8 @@ varbinder::LocalVariable *ETSObjectType::CollectSignaturesForSyntheticType(ETSFu } }; - // During function reference resolution, if the found properties type is not a function type, then it is a - // functional interface, because no other property can be found in the methods of the class. We have to - // return the found property, because we doesn't need to create a synthetic variable for functional - // interfaces due to the fact, that by nature they behave as fields, and can't have overloads, and they are - // subjected to hiding if ((flags & PropertySearchFlags::SEARCH_STATIC_METHOD) != 0) { if (auto *found = GetOwnProperty(name); found != nullptr) { - if (found->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE)) { - // Functional interface found - return found; - } - ASSERT(found->TsType()->IsETSFunctionType()); addSignature(found); } @@ -165,11 +148,6 @@ varbinder::LocalVariable *ETSObjectType::CollectSignaturesForSyntheticType(ETSFu if ((flags & PropertySearchFlags::SEARCH_INSTANCE_METHOD) != 0) { if (auto *found = GetOwnProperty(name); found != nullptr) { - if (found->HasFlag(varbinder::VariableFlags::METHOD_REFERENCE)) { - // Functional interface found - return found; - } - ASSERT(found->TsType()->IsETSFunctionType()); addSignature(found); } diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 24d5b1b019..7ecf3b997d 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -594,6 +594,7 @@ private: ASSERT(declNode_->IsTSInterfaceDeclaration() && declNode_->AsTSInterfaceDeclaration()->TypeParams()); return declNode_->AsTSInterfaceDeclaration()->TypeParams(); } + varbinder::LocalVariable *SearchFieldsDecls(const util::StringView &name, PropertySearchFlags flags) const; ArenaAllocator *allocator_; util::StringView name_; diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 8fcfd8a0cd..e2c07a3c26 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -171,10 +171,14 @@ std::pair MemberExpression::Resolve return {checker->GetTypeOfVariable(resolveRes[0]->Variable()), nullptr}; } case 2U: { - // ETSExtensionFuncHelperType(class_method_type, extension_method_type) - auto *resolvedType = checker->CreateETSExtensionFuncHelperType( - checker->GetTypeOfVariable(resolveRes[1]->Variable())->AsETSFunctionType(), - checker->GetTypeOfVariable(resolveRes[0]->Variable())->AsETSFunctionType()); + auto classMethodType = checker->GetTypeOfVariable(resolveRes[1]->Variable()); + auto extensionMethodType = checker->GetTypeOfVariable(resolveRes[0]->Variable()); + auto *resolvedType = extensionMethodType; + if (classMethodType->IsETSFunctionType()) { + ASSERT(extensionMethodType->IsETSFunctionType()); + resolvedType = checker->CreateETSExtensionFuncHelperType(classMethodType->AsETSFunctionType(), + extensionMethodType->AsETSFunctionType()); + } return {resolvedType, nullptr}; } default: { diff --git a/ets2panda/test/compiler/ets/identifierReference12-expected.txt b/ets2panda/test/compiler/ets/identifierReference12-expected.txt index c41ed2bceb..f568a39d0b 100644 --- a/ets2panda/test/compiler/ets/identifierReference12-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference12-expected.txt @@ -888,4 +888,4 @@ } } } -TypeError: Property 'foo' does not exist on type 'B' [identifierReference12.ets:24:20] +TypeError: This expression is not callable. [identifierReference12.ets:24:13] diff --git a/ets2panda/test/compiler/ets/invalidIndirectInheritanceFromClass-expected.txt b/ets2panda/test/compiler/ets/invalidIndirectInheritanceFromClass-expected.txt index 33cb453b9b..115f9f8170 100644 --- a/ets2panda/test/compiler/ets/invalidIndirectInheritanceFromClass-expected.txt +++ b/ets2panda/test/compiler/ets/invalidIndirectInheritanceFromClass-expected.txt @@ -1383,4 +1383,4 @@ } } } -TypeError: Cannot inherit from class C, because field x is inherited with a different declaration type [invalidIndirectInheritanceFromClass.ets:25:17] +TypeError: This expression is not callable. [invalidIndirectInheritanceFromClass.ets:28:15] diff --git a/ets2panda/test/compiler/ets/invalidIndirectInheritanceFromInterface-expected.txt b/ets2panda/test/compiler/ets/invalidIndirectInheritanceFromInterface-expected.txt index e6a9aa7fd9..7b2e3b54d9 100644 --- a/ets2panda/test/compiler/ets/invalidIndirectInheritanceFromInterface-expected.txt +++ b/ets2panda/test/compiler/ets/invalidIndirectInheritanceFromInterface-expected.txt @@ -1306,4 +1306,4 @@ } } } -TypeError: Cannot inherit from class C, because field x is inherited with a different declaration type [invalidIndirectInheritanceFromInterface.ets:25:17] +TypeError: This expression is not callable. [invalidIndirectInheritanceFromInterface.ets:28:15] diff --git a/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt b/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt index bb1005989a..4d61cbfbaa 100644 --- a/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt +++ b/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt @@ -702,4 +702,3 @@ } } } -TypeError: Cannot inherit from class A, because field a is inherited with a different declaration type [invalidInheritance3.ets:20:17] diff --git a/ets2panda/test/compiler/ets/invalidInheritanceFromClass-expected.txt b/ets2panda/test/compiler/ets/invalidInheritanceFromClass-expected.txt index 13e1ac543f..9ec98d345b 100644 --- a/ets2panda/test/compiler/ets/invalidInheritanceFromClass-expected.txt +++ b/ets2panda/test/compiler/ets/invalidInheritanceFromClass-expected.txt @@ -1206,4 +1206,4 @@ } } } -TypeError: Cannot inherit from class A, because field x is inherited with a different declaration type [invalidInheritanceFromClass.ets:22:17] +TypeError: This expression is not callable. [invalidInheritanceFromClass.ets:25:15] diff --git a/ets2panda/test/compiler/ets/invalidInheritanceFromInterface-expected.txt b/ets2panda/test/compiler/ets/invalidInheritanceFromInterface-expected.txt index e91b4302b3..09abd0fd65 100644 --- a/ets2panda/test/compiler/ets/invalidInheritanceFromInterface-expected.txt +++ b/ets2panda/test/compiler/ets/invalidInheritanceFromInterface-expected.txt @@ -1129,4 +1129,4 @@ } } } -TypeError: Cannot inherit from interface A because field x is inherited with a different declaration type [invalidInheritanceFromInterface.ets:16:1] +TypeError: This expression is not callable. [invalidInheritanceFromInterface.ets:25:15] diff --git a/ets2panda/varbinder/variableFlags.h b/ets2panda/varbinder/variableFlags.h index 6cbe8917f1..dd152b2ea6 100644 --- a/ets2panda/varbinder/variableFlags.h +++ b/ets2panda/varbinder/variableFlags.h @@ -137,22 +137,21 @@ enum class VariableFlags : uint64_t { PROTECTED = 1U << 19U, PRIVATE = 1U << 20U, SYNTHETIC = 1U << 21U, - METHOD_REFERENCE = 1U << 22U, - LOCAL = 1U << 23U, - - LEXICAL = 1U << 24U, - LOOP_DECL = 1U << 25U, - PER_ITERATION = 1U << 26U, - LEXICAL_VAR = 1U << 27U, - HOIST = 1U << 28U, - VAR = 1U << 29U, - INITIALIZED = 1U << 30U, - LEXICAL_BOUND = 1U << 31U, - - BUILTIN_TYPE = 1ULL << 32ULL, - - BOXED = 1ULL << 33ULL, - GETTER_SETTER = 1ULL << 34ULL, + LOCAL = 1U << 22U, + + LEXICAL = 1U << 23U, + LOOP_DECL = 1U << 24U, + PER_ITERATION = 1U << 25U, + LEXICAL_VAR = 1U << 26U, + HOIST = 1U << 27U, + VAR = 1U << 28U, + INITIALIZED = 1U << 29U, + LEXICAL_BOUND = 1U << 30U, + + BUILTIN_TYPE = 1ULL << 31ULL, + + BOXED = 1ULL << 32ULL, + GETTER_SETTER = 1ULL << 33ULL, HOIST_VAR = HOIST | VAR, CLASS_OR_INTERFACE = CLASS | INTERFACE, -- Gitee From 79b7ff950190c56a1f77f7cda2213df8309b6f82 Mon Sep 17 00:00:00 2001 From: aleksisch Date: Thu, 15 Feb 2024 13:55:55 +0300 Subject: [PATCH 2/2] add functional inheritance test Signed-off-by: aleksisch --- .../ets/invalidInheritance4-expected.txt | 666 ++++++++++++++++++ .../test/compiler/ets/invalidInheritance4.ets | 22 + 2 files changed, 688 insertions(+) create mode 100644 ets2panda/test/compiler/ets/invalidInheritance4-expected.txt create mode 100644 ets2panda/test/compiler/ets/invalidInheritance4.ets diff --git a/ets2panda/test/compiler/ets/invalidInheritance4-expected.txt b/ets2panda/test/compiler/ets/invalidInheritance4-expected.txt new file mode 100644 index 0000000000..81bc20a805 --- /dev/null +++ b/ets2panda/test/compiler/ets/invalidInheritance4-expected.txt @@ -0,0 +1,666 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 2 + }, + "end": { + "line": 22, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "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 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 23, + "column": 1 + } + } +} +TypeError: Cannot inherit from class A, because method name is inherited with a different declaration type [invalidInheritance4.ets:20:17] diff --git a/ets2panda/test/compiler/ets/invalidInheritance4.ets b/ets2panda/test/compiler/ets/invalidInheritance4.ets new file mode 100644 index 0000000000..9da1a110da --- /dev/null +++ b/ets2panda/test/compiler/ets/invalidInheritance4.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021-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. + */ + +class A { + name: () => String +} + +class B extends A { + name(): int {} +} -- Gitee