diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 912dd11f40e02c16def7bf72aa490607a2a316e2..3bdd25e1008a2dec01763f449067ee72bf63ee71 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -129,7 +129,10 @@ ForUpdateStatement *ForUpdateStatement::Clone(ArenaAllocator *const allocator, A { auto *const init = init_->Clone(allocator, nullptr); auto *const test = test_->Clone(allocator, nullptr)->AsExpression(); - auto *const update = update_->Clone(allocator, nullptr)->AsExpression(); + Expression *update = nullptr; + if (update_ != nullptr) { + update = update_->Clone(allocator, nullptr)->AsExpression(); + } auto *const body = body_->Clone(allocator, nullptr)->AsStatement(); auto *const clone = util::NodeAllocator::ForceSetParent(allocator, init, test, update, body); diff --git a/ets2panda/test/ast/compiler/ets/nullable_clone_update.ets b/ets2panda/test/ast/compiler/ets/nullable_clone_update.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6c70c60ba24c326cb2d1f63768d038233994719 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/nullable_clone_update.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024-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 util from '@ohos.util'; + +export function Utf8ArrayToStr(array: Uint8Array, encoding: string = 'utf8'): string { + return innerUtf8ArrayToStr(array) +} + +let innerUtf8ArrayToStr = (() => { + let charCache : string[] = new Array(512); // Preallocate the cache for the common single byte chars + let charFromCodePt = String.fromCodePoint || String.fromCharCode; + let result: string[] = []; + return (array:Uint8Array) => { + let codePt : number = 0; + let byte1 : number = 0; + let buffLen = array.length; + result.length = 0; + for (let i = 0; i < buffLen;) { + byte1 = array[i++]; + + if (byte1 <= 0x7F) { + codePt = byte1; + } else if (byte1 <= 0xDF) { + codePt = ((byte1 & 0x1F) << 6) | (array[i++] & 0x3F); + } else if (byte1 <= 0xEF) { + codePt = ((byte1 & 0x0F) << 12) | ((array[i++] & 0x3F) << 6) | (array[i++] & 0x3F); + } else if (String.fromCodePoint(byte1)) { + codePt = ((byte1 & 0x07) << 18) | ((array[i++] & 0x3F) << 12) | + ((array[i++] & 0x3F) << 6) | (array[i++] & 0x3F); + } else { + codePt = 63; // Cannot convert four byte code points, so use '?' instead + i += 3; + } + + result.push(charCache[codePt] || (charCache[codePt] = charFromCodePt(codePt))); + } + let r = result.join(''); + return r; + }; +})(); + +export function str2Uint8Array(content: string) { + for (let i = 0; i < content.length; i++) { + content.charCodeAt(i) + } +} + +/* @@? 16:18 Error TypeError: Cannot find default imported element in the target */ +/* @@? 23:34 Error TypeError: Type 'Array' is generic but type argument were not provided. */ +/* @@? 24:55 Error TypeError: Overloaded method is used as value */