diff --git a/ets2panda/checker/ets/conversion.cpp b/ets2panda/checker/ets/conversion.cpp index 90c5d2f5be896c9e5a163c814e21236480cb8378..71de0b5aff59841760fa87fc511e22c287f1f2d5 100644 --- a/ets2panda/checker/ets/conversion.cpp +++ b/ets2panda/checker/ets/conversion.cpp @@ -68,14 +68,15 @@ bool IsAllowedNarrowingReferenceConversionObjectObject(TypeRelation *const relat // 3. S is a class type, T is an interface type, and S names class not marked as final. if (source->HasObjectFlag(ETSObjectFlags::CLASS) && target->HasObjectFlag(ETSObjectFlags::INTERFACE) && - !source->GetDeclNode()->IsFinal()) { + source->GetDeclNode() != nullptr && !source->GetDeclNode()->IsFinal()) { return true; } // 4. S is a class type, T is an interface type, and S names a class that is marked as final and that // implements the interface named by T. if (source->HasObjectFlag(ETSObjectFlags::CLASS) && target->HasObjectFlag(ETSObjectFlags::INTERFACE) && - source->GetDeclNode()->IsFinal() && relation->IsSupertypeOf(source, target)) { + source->GetDeclNode() != nullptr && source->GetDeclNode()->IsFinal() && + relation->IsSupertypeOf(source, target)) { return true; } diff --git a/ets2panda/test/ast/compiler/ets/reference_conversion.ets b/ets2panda/test/ast/compiler/ets/reference_conversion.ets new file mode 100644 index 0000000000000000000000000000000000000000..9bc2aaead19453fe3c948b3dc70b068c958fb5ee --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/reference_conversion.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. + */ + +import A C, X as D} from 'z'; + +interface D { + f : nuted + +/* @@? 16:10 Error SyntaxError: Unexpected token, expected 'from'. */ +/* @@? 16:11 Error SyntaxError: Unexpected token, expected 'from'. */ +/* @@? 16:13 Error SyntaxError: Unexpected token, expected string literal. */ +/* @@? 16:13 Error TypeError: Cannot cast type '"*ERROR_LITERAL*"' to 'D' */ +/* @@? 16:19 Error SyntaxError: Unexpected token '}'. */ +/* @@? 16:21 Error SyntaxError: Unexpected token 'from'. */ +/* @@? 16:21 Error TypeError: Unresolved reference from */ +/* @@? 16:26 Error SyntaxError: Unexpected token 'z'. */ +/* @@? 19:9 Error TypeError: Cannot find type 'nuted'. */ +/* @@? 31:1 Error SyntaxError: Unexpected token, expected '}'. */