已合并
remove cts-ignore of static member inhenritance #10708
remove cts-ignore of static member inhenritance #10708
已合并
XuMoheng创建于 5月14日
共 7 个文件变更+59-16
@@ -62,6 +62,43 @@ std::pair<varbinder::Variable *, const ETSObjectType *> ETSChecker::FindVariable
62 return {resolved, classType};62 return {resolved, classType};
63}63}
64 64 
65+static const ETSObjectType *GetStaticPropertyDeclType(const varbinder::LocalVariable *property)
66+{
67+ if (!ETSChecker::IsVariableStatic(property)) {
68+ return nullptr;
69+ }
70+ 
71+ if (property->TsType() != nullptr && property->TsType()->IsETSMethodType()) {
fanglou
fangloufanglou5月15日

【提示】

改动建议
71
+ auto tsType = property->TsType();
71
- if (property->TsType() != nullptr && property->TsType()->IsETSMethodType()) {
72
+ if (tsType != nullptr && tsType->IsETSMethodType()) {
应用建议

减少函数调用

likedislike
72+ auto *funcType = property->TsType()->AsETSFunctionType();
73+ if (funcType->CallSignatures().empty()) {
74+ return nullptr;
75+ }
76+ 
77+ auto *owner = funcType->CallSignatures()[0]->Owner();
fanglou
fangloufanglou5月15日

【一般】owner可以在外层统一声明,内层赋值

likedislike
78+ if (owner == nullptr || owner->GetDeclNode() == nullptr || !owner->GetDeclNode()->IsClassDefinition()) {
79+ return nullptr;
80+ }
81+ 
82+ return owner;
83+ }
84+ 
85+ if (property->Declaration() == nullptr || property->Declaration()->Node() == nullptr) {
fanglou
fangloufanglou5月15日

【提示】同上71行

likedislike
86+ return nullptr;
87+ }
88+ 
89+ auto *owner = property->Declaration()->Node()->Parent();
90+ if (owner == nullptr || !owner->IsClassDefinition() || owner->AsClassDefinition()->TsType() == nullptr) {
91+ return nullptr;
92+ }
93+ 
94+ auto *ownerTsType = owner->AsClassDefinition()->TsType();
95+ if (ownerTsType == nullptr || !ownerTsType->IsETSObjectType()) {
96+ return nullptr;
97+ }
98+ 
99+ return ownerTsType->AsETSObjectType();
100+}
101+ 
65varbinder::Variable *ETSChecker::FindVariableInGlobal(const ir::Identifier *const identifier,102varbinder::Variable *ETSChecker::FindVariableInGlobal(const ir::Identifier *const identifier,
66 const varbinder::ResolveBindingOptions options)103 const varbinder::ResolveBindingOptions options)
67{104{
@@ -186,7 +223,10 @@ void ETSChecker::NotResolvedError(ir::Identifier *const ident, const varbinder::
186 }223 }
187 224 
188 if (IsVariableStatic(classVar)) {225 if (IsVariableStatic(classVar)) {
189- LogError(diagnostic::STATIC_PROP_INVALID_CTX, {ident->Name(), classType}, ident->Start());226+ const auto *declaringType =
227+ classVar->IsLocalVariable() ? GetStaticPropertyDeclType(classVar->AsLocalVariable()) : nullptr;
228+ LogError(diagnostic::STATIC_PROP_INVALID_CTX,
229+ {ident->Name(), declaringType != nullptr ? declaringType : classType}, ident->Start());
190 } else {230 } else {
191 if (HasStatus(CheckerStatus::IN_STATIC_CONTEXT)) {231 if (HasStatus(CheckerStatus::IN_STATIC_CONTEXT)) {
192 LogUnresolvedReferenceError(ident);232 LogUnresolvedReferenceError(ident);
@@ -2687,6 +2687,8 @@ void ETSChecker::ValidateNamespaceProperty(varbinder::Variable *property, const
2687 }2687 }
2688}2688}
2689 2689 
2690+static const ETSObjectType *GetStaticPropertyDeclType(const varbinder::LocalVariable *property);
fanglou
fangloufanglou5月15日

【提示】声明可以放在头文件

likedislike
2691+ 
2690void ETSChecker::ValidateResolvedProperty(varbinder::LocalVariable **property, const ETSObjectType *const target,2692void ETSChecker::ValidateResolvedProperty(varbinder::LocalVariable **property, const ETSObjectType *const target,
2691 const ir::Identifier *const ident, const PropertySearchFlags flags)2693 const ir::Identifier *const ident, const PropertySearchFlags flags)
2692{2694{
@@ -2725,7 +2727,10 @@ void ETSChecker::ValidateResolvedProperty(varbinder::LocalVariable **property, c
2725 *property = newProp; // trying to recover as much as possible; log the error but treat the property as legal2727 *property = newProp; // trying to recover as much as possible; log the error but treat the property as legal
2726 2728 
2727 if (IsVariableStatic(newProp)) {2729 if (IsVariableStatic(newProp)) {
2728- LogError(diagnostic::PROP_IS_STATIC, {ident->Name(), target->Name()}, ident->Start());2730+ const auto *declaringType =
2731+ newProp->IsLocalVariable() ? GetStaticPropertyDeclType(newProp->AsLocalVariable()) : nullptr;
2732+ LogError(diagnostic::PROP_IS_STATIC, {ident->Name(), declaringType != nullptr ? declaringType : target},
2733+ ident->Start());
2729 return;2734 return;
2730 }2735 }
2731 2736 
@@ -1,5 +1,5 @@
1/*1/*
2- * Copyright (c) 2024-2025 Huawei Device Co., Ltd.2+ * Copyright (c) 2024-2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -29,4 +29,4 @@ Error().fromEntries() {}
29/* @@? 23:1 Error Semantic error ESE0127: No matching call signature for foos() */29/* @@? 23:1 Error Semantic error ESE0127: No matching call signature for foos() */
30/* @@? 26:1 Error Semantic error ESE0124: Expected 1 arguments, got 0. */30/* @@? 26:1 Error Semantic error ESE0124: Expected 1 arguments, got 0. */
31/* @@? 26:1 Error Semantic error ESE0127: No matching call signature for fromEntries() */31/* @@? 26:1 Error Semantic error ESE0127: No matching call signature for fromEntries() */
32-/* @@? 26:9 Error Semantic error ESE0207: 'fromEntries' is a static property of 'Error' */32+/* @@? 26:9 Error Semantic error ESE0207: 'fromEntries' is a static property of 'Object' */
@@ -1,5 +1,5 @@
1/*1/*
2- * Copyright (c) 2024-2025 Huawei Device Co., Ltd.2+ * Copyright (c) 2024-2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -21,4 +21,4 @@ let a = new G<String>();
21a.y++;21a.y++;
22 22 
23 23 
24-/* @@? 21:3 Error Semantic error ESE0207: 'y' is a static property of 'G' */24+/* @@? 21:3 Error Semantic error ESE0207: 'y' is a static property of 'G<T>' */
@@ -1,5 +1,5 @@
1/*1/*
2- * Copyright (c) 2024-2025 Huawei Device Co., Ltd.2+ * Copyright (c) 2024-2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -23,4 +23,4 @@ let a = new G<String>();
23a.y();23a.y();
24 24 
25 25 
26-/* @@? 23:3 Error Semantic error ESE0207: 'y' is a static property of 'G' */26+/* @@? 23:3 Error Semantic error ESE0207: 'y' is a static property of 'G<T>' */
@@ -1,5 +1,5 @@
1-/*1+/**
2- * Copyright (c) 2025 Huawei Device Co., Ltd.2+ * Copyright (c) 2025-2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -24,5 +24,4 @@ function main() {
24 bb.foo()24 bb.foo()
25}25}
26 26 
27- 27+/* @@? 24:6 Error Semantic error ESE0207: 'foo' is a static property of 'A' */
28-/* @@? 24:6 Error Semantic error ESE0207: 'foo' is a static property of 'B' */
@@ -1,5 +1,5 @@
1-/*1+/**
2- * Copyright (c) 2025 Huawei Device Co., Ltd.2+ * Copyright (c) 2025-2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -23,5 +23,4 @@ class B extends A {
23 }23 }
24}24}
25 25 
26- 26+/* @@? 22:14 Error Semantic error ESE0207: 'foo' is a static property of 'A' */
27-/* @@? 22:14 Error Semantic error ESE0207: 'foo' is a static property of 'B' */