已合并
Implict export a wrong error reported #10833
Implict export a wrong error reported #10833
已合并
fanglou创建于 5月29日
共 12 个文件变更+231-17
@@ -98,7 +98,22 @@ static bool IsExpressionInClassPropertyInitializer(const ir::Expression *expr)
98 return false;98 return false;
99}99}
100 100 
101-// Helper: checks that type was declared exported101+static void LogNonExportedTypeError(ETSChecker *checker, checker::Type const *type, ir::AstNode const *decl)
102+{
103+ if (!util::Helpers::IsExported(decl) && !util::Helpers::IsStdLib(decl->Program())) {
104+ checker->LogError(diagnostic::USED_TYPE_IS_NOT_EXPORTED, {type->ToString()}, decl->Start());
105+ }
106+}
107+ 
108+static void CheckPartialTypeExport(ETSChecker *checker, checker::ETSObjectType const *partialType)
109+{
110+ auto *baseType = partialType->GetBaseType();
111+ if (baseType == nullptr || baseType->HasObjectFlag(ETSObjectFlags::BUILTIN_TYPE)) {
112+ return;
113+ }
114+ LogNonExportedTypeError(checker, static_cast<Type const *>(baseType), baseType->GetDeclNode());
115+}
116+ 
102static void CheckExport(ETSChecker *checker, checker::Type const *type)117static void CheckExport(ETSChecker *checker, checker::Type const *type)
103{118{
104 if (type == nullptr || type->IsTypeError()) {119 if (type == nullptr || type->IsTypeError()) {
@@ -106,29 +121,28 @@ static void CheckExport(ETSChecker *checker, checker::Type const *type)
106 }121 }
107 122 
108 auto const checkExported = [checker](Type const *testType) {123 auto const checkExported = [checker](Type const *testType) {
109- ir::AstNode const *decl = nullptr;
110 if (testType->IsETSObjectType()) {124 if (testType->IsETSObjectType()) {
111- if (!testType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::BUILTIN_TYPE)) {125+ if (testType->AsETSObjectType()->IsPartial()) {
112- decl = testType->AsETSObjectType()->GetDeclNode();126+ CheckPartialTypeExport(checker, testType->AsETSObjectType());
113- } else {
114 return;127 return;
115 }128 }
116- } else if (testType->IsETSTypeAliasType()) {129+ if (testType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::BUILTIN_TYPE)) {
117- decl = testType->AsETSTypeAliasType()->GetDeclNode();130+ return;
118- } else {131+ }
132+ LogNonExportedTypeError(checker, testType, testType->AsETSObjectType()->GetDeclNode());
119 return;133 return;
120 }134 }
121- 135+ if (testType->IsETSTypeAliasType()) {
122- // class AtomicInt {} need to write "export" qualifier (source136+ LogNonExportedTypeError(checker, testType, testType->AsETSTypeAliasType()->GetDeclNode());
123- // ./runtime_core/static_core/plugins/ets/stdlib/std/containers/ConcurrencyHelpers.ets) class AtomicInt {} need
124- // to write "export" qualifier (source
125- // ./runtime_core/static_core/plugins/ets/stdlib/std/concurrency/ConcurrencyHelpers.ets) class AtomicInt {} has
126- // the same code in both sources after that need to remove util::Helpers::IsStdLib() condition
127- if (!util::Helpers::IsExported(decl) && !util::Helpers::IsStdLib(decl->Program())) {
128- checker->LogError(diagnostic::USED_TYPE_IS_NOT_EXPORTED, {testType->ToString()}, decl->Start());
129 }137 }
130 };138 };
131 139 
140+ // class AtomicInt {} need to write "export" qualifier (source
141+ // ./runtime_core/static_core/plugins/ets/stdlib/std/containers/ConcurrencyHelpers.ets) class AtomicInt {} need
142+ // to write "export" qualifier (source
143+ // ./runtime_core/static_core/plugins/ets/stdlib/std/concurrency/ConcurrencyHelpers.ets) class AtomicInt {} has
144+ // the same code in both sources after that need to remove util::Helpers::IsStdLib() condition
145+ 
132 type->IterateRecursively(checkExported);146 type->IterateRecursively(checkExported);
133}147}
134 148 
@@ -0,0 +1,22 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+declare namespace api {
17+ class A{}
18+}
19+ 
20+export default api
21+ 
22+export class C extends api.A {}
Prof
ProfProf6月1日

Please also add next test:

file1.ets

 declare namespace api {
 	     class A{}
 	 }
 	 
 	 export default api

file2.ets

import {api} from file1
export class C extends api.A {}
likedislike
fanglou
fanglou
6月1日 评论:
@@ -0,0 +1,20 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+namespace api {
17+ export class A{}
18+}
19+ 
20+export class C extends api.A {}
Prof
ProfProf6月1日

Please also add next test:

file1.ets

 namespace api {
 	     export class A{}
 	 }

file2.ets

import {api} from file1
export class C extends api.A {}
likedislike
fanglou
fanglou
6月1日 评论:
@@ -0,0 +1,20 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+declare namespace api {
17+ class A{}
18+}
19+ 
20+export default api
@@ -0,0 +1,18 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+import api from './file1.ets'
17+ 
18+export class C extends api.A {}
@@ -0,0 +1,18 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+export namespace api {
17+ export class A{}
18+}
@@ -0,0 +1,18 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+import {api} from './file1.ets'
17+ 
18+export class C extends api.A {}
@@ -0,0 +1,20 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+export class A {
17+ i: int = 0
18+}
19+ 
20+export type PA = Partial<A>
@@ -0,0 +1,20 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+import {PA} from './file1.ets'
17+ 
18+export function foo(p: PA): Int|undefined {
19+ return p.i;
20+}
@@ -0,0 +1,24 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+export class A {
17+ i: int = 0
18+}
19+ 
20+export type PA = Partial<A>
21+ 
22+export function foo(p: PA): Int|undefined {
23+ return p.i;
24+}
Prof
ProfProf6月1日

Please also add next test:

file1.ets

 export class A {
 	     i: int = 0
 	 }
 	 
 	 export type PA = Partial<A>

file2.ets

import {api} from file1
 export function foo(p: PA): Int|undefined {
 	     return p.i;
 	 }
likedislike
fanglou
fanglou
6月1日 评论:
@@ -0,0 +1,21 @@
1+/**
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+class B /* @@ label */{}
17+ 
18+export type A = Partial<B>
19+ 
20+ 
21+/* @@@ label Error Semantic error ESE1236581: Type 'B' used in export declaration(s) is not exported. */
@@ -50,7 +50,6 @@ softlist:
50 - ".*/foundation/arkui/ace_engine/frameworks/.*"50 - ".*/foundation/arkui/ace_engine/frameworks/.*"
51 - ".*/foundation/arkui/ace_engine/advanced_ui_component_static/.*"51 - ".*/foundation/arkui/ace_engine/advanced_ui_component_static/.*"
52 - ".*/@ohos\\.util\\.stream\\.d\\.ets"52 - ".*/@ohos\\.util\\.stream\\.d\\.ets"
53- - ".*/@ohos\\.rpc\\.d\\.ets"
54 - ".*/@ohos\\.app\\.ability\\.insightIntent\\.d\\.ets"53 - ".*/@ohos\\.app\\.ability\\.insightIntent\\.d\\.ets"
55 - ".*/@ohos\\.uri\\.d\\.ets"54 - ".*/@ohos\\.uri\\.d\\.ets"
56 55