diff --git a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp index e74ea9ce958031501326d405317cba0fd98355ad..dce6517aacd5193e2ffe2cdbe6d6cdeb77cc24b9 100644 --- a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp +++ b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp @@ -151,12 +151,14 @@ void GenericBridgesPhase::ProcessScriptFunction(ir::ClassDefinition const *const // or have type parameters that are not modified in the derived class ES2PANDA_ASSERT(baseFunction); auto const *baseSignature1 = baseFunction->Signature()->Substitute(relation, &substitutions.baseConstraints); - if (baseSignature1 == baseFunction->Signature()) { + if (baseSignature1 == baseFunction->Signature() && + !baseSignature1->HasSignatureFlag(checker::SignatureFlags::DEFAULT)) { return; } auto *baseSignature2 = baseFunction->Signature()->Substitute(relation, &substitutions.derivedSubstitutions); - if (baseSignature2 == baseFunction->Signature()) { + if (baseSignature2 == baseFunction->Signature() && + !baseSignature2->HasSignatureFlag(checker::SignatureFlags::DEFAULT)) { return; } baseSignature2 = baseSignature2->Substitute(relation, &substitutions.derivedConstraints); @@ -177,8 +179,8 @@ void GenericBridgesPhase::ProcessScriptFunction(ir::ClassDefinition const *const // This derived overload already handles the base union signature. return; } - - if (derivedFunction == nullptr && overrides(signature, baseSignature2)) { + if ((derivedFunction == nullptr && overrides(signature, baseSignature2)) || + (baseSignature1 == baseSignature2 && baseSignature1->HasSignatureFlag(checker::SignatureFlags::DEFAULT))) { // NOTE: we don't care the possible case of mapping several derived function to the same bridge // signature. Probably sometimes we will process it correctly or issue warning notification here... derivedFunction = signature->Function(); @@ -337,6 +339,14 @@ ir::ClassDefinition *GenericBridgesPhase::ProcessClassDefinition(ir::ClassDefini auto const &superClassBody = classDefinition->Super()->TsType()->AsETSObjectType()->GetDeclNode()->AsClassDefinition()->Body(); CreateGenericBridges(classDefinition, substitutions, superClassBody); + ArenaVector interfaces = + classDefinition->Super()->TsType()->AsETSObjectType()->Interfaces(); + if (!interfaces.empty()) { + for (checker::ETSObjectType *interface : interfaces) { + auto &interfaceBody = interface->GetDeclNode()->AsTSInterfaceDeclaration()->Body()->Body(); + CreateGenericBridges(classDefinition, substitutions, interfaceBody); + } + } } return classDefinition; diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/declare1.d.ets b/ets2panda/test/runtime/ets/default_generic_bridge/declare1.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..47bb9d9b3b2265fcbe14d827bab10182f443dbf2 --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/declare1.d.ets @@ -0,0 +1,25 @@ +/* + * 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. + */ + +/*--- + tags: [not-a-test] +---*/ + +export declare interface AttributeModifier { + default applyNormalAttribute(instance: T): void +} + +export declare class AttributeUpdater implements AttributeModifier { +} diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/declare1.ets b/ets2panda/test/runtime/ets/default_generic_bridge/declare1.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5d794f799bf9d9cd1d80f87326f03dcf6e1ad17 --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/declare1.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ + +/*--- + tags: [not-a-test] +---*/ + +export interface AttributeModifier { + applyNormalAttribute(instance: T): void { + console.log("interface"); + } +} + +export class AttributeUpdater implements AttributeModifier { + applyNormalAttribute(instance: T): void { + console.log("father"); + } +} diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/declare2.d.ets b/ets2panda/test/runtime/ets/default_generic_bridge/declare2.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca66e0d87fc5f2474b0e02f4b9bf01c665aafa15 --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/declare2.d.ets @@ -0,0 +1,26 @@ +/* + * 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. + */ + +/*--- + tags: [not-a-test] +---*/ + +export declare interface AttributeModifier { + default applyNormalAttribute(instance: T): void +} + +export declare class AttributeUpdater implements AttributeModifier { + applyNormalAttribute(instance: T): void +} diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/declare2.ets b/ets2panda/test/runtime/ets/default_generic_bridge/declare2.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5d794f799bf9d9cd1d80f87326f03dcf6e1ad17 --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/declare2.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ + +/*--- + tags: [not-a-test] +---*/ + +export interface AttributeModifier { + applyNormalAttribute(instance: T): void { + console.log("interface"); + } +} + +export class AttributeUpdater implements AttributeModifier { + applyNormalAttribute(instance: T): void { + console.log("father"); + } +} diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/declare3.d.ets b/ets2panda/test/runtime/ets/default_generic_bridge/declare3.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..47bb9d9b3b2265fcbe14d827bab10182f443dbf2 --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/declare3.d.ets @@ -0,0 +1,25 @@ +/* + * 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. + */ + +/*--- + tags: [not-a-test] +---*/ + +export declare interface AttributeModifier { + default applyNormalAttribute(instance: T): void +} + +export declare class AttributeUpdater implements AttributeModifier { +} diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/declare3.ets b/ets2panda/test/runtime/ets/default_generic_bridge/declare3.ets new file mode 100644 index 0000000000000000000000000000000000000000..c26801ae919588c9c769b73bd60c0888823c28f2 --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/declare3.ets @@ -0,0 +1,27 @@ +/* + * 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. + */ + +/*--- + tags: [not-a-test] +---*/ + +export interface AttributeModifier { + applyNormalAttribute(instance: T): void { + console.log("interface"); + } +} + +export class AttributeUpdater implements AttributeModifier { +} diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/index1.ets b/ets2panda/test/runtime/ets/default_generic_bridge/index1.ets new file mode 100644 index 0000000000000000000000000000000000000000..d14fafc5dbb07ab2dc55c814f55d4a01742ba620 --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/index1.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/*--- + tags: [compile-only] +---*/ + +import { AttributeModifier, AttributeUpdater } from "./declare1" + + +class ButtonAttribute { } + +class TestAttributeUpdater extends AttributeUpdater { + applyNormalAttribute(instance: ButtonAttribute): void { + console.log("son"); + } +} + +function foo(tst: AttributeModifier) { + tst.applyNormalAttribute(new ButtonAttribute()); +} + +foo(new TestAttributeUpdater()); diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/index2.ets b/ets2panda/test/runtime/ets/default_generic_bridge/index2.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b2addc5b934dfc8dde02e66c27851b39515366a --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/index2.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/*--- + tags: [compile-only] +---*/ + +import { AttributeModifier, AttributeUpdater } from "./declare2" + + +class ButtonAttribute { } + +class TestAttributeUpdater extends AttributeUpdater { + applyNormalAttribute(instance: ButtonAttribute): void { + console.log("son"); + } +} + +function foo(tst: AttributeModifier) { + tst.applyNormalAttribute(new ButtonAttribute()); +} + +foo(new TestAttributeUpdater()); diff --git a/ets2panda/test/runtime/ets/default_generic_bridge/index3.ets b/ets2panda/test/runtime/ets/default_generic_bridge/index3.ets new file mode 100644 index 0000000000000000000000000000000000000000..dcfd1b955a2ca9cba50ffb2bd317c1158c06880b --- /dev/null +++ b/ets2panda/test/runtime/ets/default_generic_bridge/index3.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/*--- + tags: [compile-only] +---*/ + +import { AttributeModifier, AttributeUpdater } from "./declare3" + + +class ButtonAttribute { } + +class TestAttributeUpdater extends AttributeUpdater { + applyNormalAttribute(instance: ButtonAttribute): void { + console.log("son"); + } +} + +function foo(tst: AttributeModifier) { + tst.applyNormalAttribute(new ButtonAttribute()); +} + +foo(new TestAttributeUpdater());