diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 110ba4ec5c7262334d34698bc67f69de4ef47232..0d040409b431b9c326a415baf4e3834d08c4daa9 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1834,7 +1834,8 @@ static Type *TransformTypeForMethodReference(ETSChecker *checker, ir::Expression }; ir::Expression *expr = use; - while (expr->Parent()->IsMemberExpression() && expr->Parent()->AsMemberExpression()->Property() == expr) { + while (expr->Parent()->IsMemberExpression() && !expr->Parent()->AsMemberExpression()->IsComputed() && + expr->Parent()->AsMemberExpression()->Property() == expr) { expr = expr->Parent()->AsMemberExpression(); } if (expr->Parent()->IsCallExpression() && expr->Parent()->AsCallExpression()->Callee() == expr) { diff --git a/ets2panda/test/ast/compiler/ets/incorrect_call_getter.ets b/ets2panda/test/ast/compiler/ets/incorrect_call_getter.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b4c4d31db21beb97a50f7bd84b2f17621ac65be --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/incorrect_call_getter.ets @@ -0,0 +1,37 @@ +/* + * 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 inter { + gett(k: number): number; +} + +class Getter { + $_get(index:number) {} +} + +export class ConM implements inter { + private buckets: Getter = new Getter(); + + private getBucket(k: int) { + this.buckets[this.gett](k) + } +} + +/* @@? 22:10 Error TypeError: 'The special predefined method '$_get' shouldn't have void return type. */ +/* @@? 25:36 Error TypeError: ConM is not abstract and does not override abstract method gett(k: Double): Double in inter */ +/* @@? 29:9 Error TypeError: No matching indexing signature for $_get((k: Double) => Double) */ +/* @@? 29:22 Error TypeError: Type '(k: Double) => Double' is not compatible with type 'Double' at index 1 */ +/* @@? 29:22 Error TypeError: Cannot find index access method with the required signature. */