diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 51e0dad3cdd61c14f1ee9055ae3bd45a8278f6e0..1fce5c424214444d783af41276b429b8e50d0430 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1849,6 +1849,10 @@ Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) } ES2PANDA_ASSERT(name->IsIdentifier()); + if (name->AsIdentifier()->Variable() == nullptr) { + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) + VarBinder()->AsETSBinder()->LookupTypeReference(name->AsIdentifier()); + } auto *const var = name->AsIdentifier()->Variable(); ES2PANDA_ASSERT(var != nullptr); diff --git a/ets2panda/compiler/lowering/ets/recordLowering.cpp b/ets2panda/compiler/lowering/ets/recordLowering.cpp index 889c864962e6a11ad5d428150f30d55ced14c857..32c30d0353d7a8b87fce58a359ffeb5afa2a3c5d 100644 --- a/ets2panda/compiler/lowering/ets/recordLowering.cpp +++ b/ets2panda/compiler/lowering/ets/recordLowering.cpp @@ -108,12 +108,8 @@ void RecordLowering::CheckDuplicateKey(KeySetType &keySet, ir::ObjectExpression ctx->GetChecker()->AsETSChecker()->LogError(diagnostic::OBJ_LIT_PROP_NAME_COLLISION, {}, expr->Start()); break; } - case ir::AstNodeType::IDENTIFIER: { - ctx->GetChecker()->AsETSChecker()->LogError(diagnostic::OBJ_LIT_UNKNOWN_PROP, {}, expr->Start()); - break; - } default: { - ES2PANDA_UNREACHABLE(); + ctx->GetChecker()->AsETSChecker()->LogError(diagnostic::OBJ_LIT_UNKNOWN_PROP, {}, expr->Start()); break; } } diff --git a/ets2panda/test/ast/compiler/ets/arrow_function_call_as_record_property_key.ets b/ets2panda/test/ast/compiler/ets/arrow_function_call_as_record_property_key.ets new file mode 100644 index 0000000000000000000000000000000000000000..aac66bdd5465ff3d70694377378bad0d3ae7ac2c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/arrow_function_call_as_record_property_key.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ + +const a: Record = { + [((): number => 2)()]: '1' +} + +const b: Record number> = { + [(():number => +("foo"))()]: function (y: string): number { + return y.length; + }, + [(():number => +("bar"))()]: (y: string):number => y.length +}; + +/* @@? 21:20 Error TypeError: Wrong operand type for unary expression */ +/* @@? 21:34 Error SyntaxError: Function expressions are not supported, use arrow functions instead */ +/* @@? 24:20 Error TypeError: Wrong operand type for unary expression */