diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index ca365e2a61a38520779e0572b1f9310578e60b12..a218222cd8049db39dde4694544ac5ed6d7a7e68 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1696,6 +1696,11 @@ static Type *TransformTypeForMethodReference(ETSChecker *checker, ir::Expression } } + if (signatures.empty()) { + checker->LogError(diagnostic::ABSTRACT_METHOD_AS_VALUE, getUseSite()); + return checker->GlobalTypeError(); + } + if (signatures.size() > 1U) { checker->LogError(diagnostic::OVERLOADED_METHOD_AS_VALUE, getUseSite()); return checker->GlobalTypeError(); diff --git a/ets2panda/test/ast/compiler/ets/abstract_value_incompatible.ets b/ets2panda/test/ast/compiler/ets/abstract_value_incompatible.ets new file mode 100644 index 0000000000000000000000000000000000000000..7b55e20d954821a5843df4bc35e2657512441fa4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/abstract_value_incompatible.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. + */ + +interface MqttClient { + publish(): void; +} + +class MockMqttClient implements MqttClient { + publish(): void {} +} + +const client = new MockMqttClient() as MqttClient; +client.publish + +/* @@? 25:8 Error TypeError: Abstract method is used as value */ diff --git a/ets2panda/util/diagnostic/semantic.yaml b/ets2panda/util/diagnostic/semantic.yaml index 4c4ae2e28ecd4f21ea96d41b0697c01a66857615..24a7e571dc3deaa33e2d2f92348e9418c4895ee7 100644 --- a/ets2panda/util/diagnostic/semantic.yaml +++ b/ets2panda/util/diagnostic/semantic.yaml @@ -1514,3 +1514,7 @@ semantic: - name: DYMANIC_INIT_WITH_OBJEXPR id: 382 message: "Dymanic Type {} cannot be initialize with an object expression" + +- name: ABSTRACT_METHOD_AS_VALUE + id: 383 + message: "Abstract method is used as value"