diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 74631ae9763e2b213ee071ef4526bb980238433b..bdc374e0280f864ad60ac44c7c1b937896efe16d 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -985,6 +985,11 @@ checker::Type *ETSAnalyzer::Check(ir::ArrayExpression *expr) const return checker->TypeError(expr, diagnostic::UNRESOLVABLE_ARRAY, expr->Start()); } + if (preferredType->IsETSTupleType()) { + if (!checker->IsArrayExprSizeValidForTuple(expr, preferredType->AsETSTupleType())) { + return checker->InvalidateType(expr); + } + } expr->SetTsType(preferredType); if (!preferredType->IsETSResizableArrayType() && !preferredType->IsETSTupleType()) { ES2PANDA_ASSERT(preferredType->IsETSArrayType()); diff --git a/ets2panda/test/ast/compiler/ets/tuple_types_13_neg.ets b/ets2panda/test/ast/compiler/ets/tuple_types_13_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad1ae6a543b281bdc04928422b3442147d80d463 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/tuple_types_13_neg.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + +function getFloatTuple(): [float, float, float, float, float] { + return []; +} + +let x: [float, float, float, float, float] = [] + +/* @@? 17:12 Error TypeError: Initializer has 0 elements, but tuple requires 5 */ +/* @@? 20:46 Error TypeError: Initializer has 0 elements, but tuple requires 5 */ diff --git a/ets2panda/test/ast/parser/ets/readonly-parameter-test/Readonly-with-ArrayType-test2.ets b/ets2panda/test/ast/parser/ets/readonly-parameter-test/Readonly-with-ArrayType-test2.ets index 7656872082259533c237005afc004ffbbcc3a816..a5d161c0132d39f6fc6277369a2201835c16536f 100644 --- a/ets2panda/test/ast/parser/ets/readonly-parameter-test/Readonly-with-ArrayType-test2.ets +++ b/ets2panda/test/ast/parser/ets/readonly-parameter-test/Readonly-with-ArrayType-test2.ets @@ -16,7 +16,7 @@ function foo (p: [int, string]) { } -let x: Readonly<[int, string]> = [] +let x: Readonly<[int, string]> = [1, 'a'] /* @@ label */foo(/* @@ label1 */x) /* @@@ label1 Error TypeError: Type 'readonly [Int, String]' is not compatible with type '[Int, String]' at index 1 */ diff --git a/ets2panda/test/ast/parser/ets/readonly-parameter-test/readonly-parameter-test5.ets b/ets2panda/test/ast/parser/ets/readonly-parameter-test/readonly-parameter-test5.ets index c070f2aba93e0138a6a8cce31b73688f519f8c67..b8f77f76e3422532e1d8435d2b26614d82aa4637 100644 --- a/ets2panda/test/ast/parser/ets/readonly-parameter-test/readonly-parameter-test5.ets +++ b/ets2panda/test/ast/parser/ets/readonly-parameter-test/readonly-parameter-test5.ets @@ -16,7 +16,7 @@ function foo (p: [int, string]) { } -let x: readonly [int, string] = [] +let x: readonly [int, string] = [1, 'a'] /* @@ label */foo(/* @@ label1 */x) /* @@@ label Error TypeError: No matching call signature for foo(readonly [Int, String]) */