diff --git a/ets2panda/ast_verifier/helpers.cpp b/ets2panda/ast_verifier/helpers.cpp index a2179fc411ba0b24db631a82db400ba318fc1b32..ba2f9d53c48b5318895685faf81ecc6af4e024f3 100644 --- a/ets2panda/ast_verifier/helpers.cpp +++ b/ets2panda/ast_verifier/helpers.cpp @@ -268,7 +268,8 @@ bool ValidateVariableAccess(const varbinder::LocalVariable *propVar, const ir::M // NOTE: need to refactor: type of member expression object can be obtained via // me->ObjType() or me->Object()->TsType() and they may differ!!!! - if (auto objType = const_cast(ast)->Object()->TsType(); objType->IsETSUnionType()) { + if (auto objType = const_cast(ast)->Object()->TsType(); + objType != nullptr && objType->IsETSUnionType()) { bool res = true; for (auto type : objType->AsETSUnionType()->ConstituentTypes()) { const_cast(ast)->SetObjectType(type->AsETSObjectType()); diff --git a/ets2panda/compiler/lowering/ets/unboxLowering.cpp b/ets2panda/compiler/lowering/ets/unboxLowering.cpp index b33a59d270584c698ec77ae62812a7015fb7b121..0cf2d12eff6a3e345a513f0cd37bb6cfb7a665e1 100644 --- a/ets2panda/compiler/lowering/ets/unboxLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unboxLowering.cpp @@ -1193,7 +1193,7 @@ struct UnboxVisitor : public ir::visitor::EmptyAstVisitor { if (mexpr->Property()->Variable()->Declaration() != nullptr && mexpr->Property()->Variable()->Declaration()->Node() != nullptr && mexpr->Property()->Variable()->Declaration()->Node()->IsTyped() && - !mexpr->Object()->TsType()->IsETSAnyType()) { + mexpr->Object()->TsType() != nullptr && !mexpr->Object()->TsType()->IsETSAnyType()) { HandleDeclarationNode(uctx_, mexpr->Property()->Variable()->Declaration()->Node()); propType = mexpr->Property()->Variable()->Declaration()->Node()->AsTyped()->TsType(); } else if (mexpr->Property()->Variable()->TsType() != nullptr) { @@ -1219,7 +1219,8 @@ struct UnboxVisitor : public ir::visitor::EmptyAstVisitor { mexpr->Property()->AsIdentifier()->Name() == "length") { mexpr->SetTsType(uctx_->checker->GlobalIntType()); } - if (mexpr->Object()->TsType()->IsETSPrimitiveType() && !IsStaticMemberExpression(mexpr)) { + if (mexpr->Object()->TsType() != nullptr && mexpr->Object()->TsType()->IsETSPrimitiveType() && + !IsStaticMemberExpression(mexpr)) { // NOTE(gogabr): need to handle some elementary method calls as intrinsics mexpr->SetObject(InsertBoxing(uctx_, mexpr->Object())); } diff --git a/ets2panda/test/ast/compiler/ets/declaration_default_values.ets b/ets2panda/test/ast/compiler/ets/declaration_default_values.ets new file mode 100644 index 0000000000000000000000000000000000000000..373f0f09c56c954c80a5f7e7e6ebf6661d607dda --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/declaration_default_values.ets @@ -0,0 +1,38 @@ +/* + * 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. + */ + +namespace MyNamespace { + export enum MyEnum { + EnumField1 = 0, + EnumField2 = 1 + } +} + +@interface ClassAnnotation { + field1: MyNamespace.MyEnum = MyNamespace.MyEnum.EnumField1; +} + + +@ClassAnnotation +class MyClass { + field2: MyNamespace.MyEnum = MyNamespace.MyEnum.EnumField2; +} + +function test() { + let myClass = new MyClass(); + arktest.assertEQ(myClass.field2, 1); +} + +test()