mirror of
https://gitee.com/openharmony/arkcompiler_runtime_core
synced 2024-11-27 00:41:14 +00:00
!2728 [ArkTS][StdLib] Runtime error on Array with T|null
Merge pull request !2728 from AleksanderSotov/array-set-null
This commit is contained in:
commit
e7ce89fba5
@ -102,7 +102,7 @@ export class Array<T> implements ReadonlyArray<T>, Iterable<T> {
|
||||
if (idx >= this.actualLength) {
|
||||
throw new RangeError("Out of bounds")
|
||||
}
|
||||
this.buffer[idx] = val as Object
|
||||
this.buffer[idx] = val
|
||||
}
|
||||
|
||||
private $_set_unsafe(idx: int, val: T): void {
|
||||
@ -1944,7 +1944,13 @@ export class Array<T> implements ReadonlyArray<T>, Iterable<T> {
|
||||
return ""
|
||||
}
|
||||
const sepReal = __runtimeIsSameReference(sep, undefined) ? "," : sep!
|
||||
let sb = new StringBuilder(new String(this.$_get_unsafe(0)))
|
||||
// NOTE(aleksander-sotov) We can't call String constructor here due to internal issue 18583
|
||||
const first_el = this.$_get_unsafe(0)
|
||||
let first_str = "undefined"
|
||||
if (!__runtimeIsSameReference(first_el, undefined)) {
|
||||
first_str = new String(first_el)
|
||||
}
|
||||
let sb = new StringBuilder(first_str)
|
||||
for (let i: int = 1; i < this.actualLength; i++) {
|
||||
const tmp = this.$_get_unsafe(i)
|
||||
sb.append(sepReal);
|
||||
|
@ -620,7 +620,13 @@
|
||||
return ""
|
||||
}
|
||||
const sepReal = __runtimeIsSameReference(sep, undefined) ? "," : sep!
|
||||
let sb = new StringBuilder(new String(<%= get_unsafe.(this, '0') %>))
|
||||
<% if el_type == "T" %>// NOTE(aleksander-sotov) We can't call String constructor here due to internal issue 18583
|
||||
const first_el = <%= get_unsafe.(this, '0') %>
|
||||
let first_str = "undefined"
|
||||
if (!__runtimeIsSameReference(first_el, undefined)) {
|
||||
first_str = new String(first_el)
|
||||
}
|
||||
let sb = new StringBuilder(first_str)<% else %>let sb = new StringBuilder(new String(<%= get_unsafe.(this, '0') %>))<% end %>
|
||||
for (let i: int = 1; i < <%= this_len_int %>; i++) {
|
||||
const tmp = <%= get_unsafe.(this, 'i') %>
|
||||
sb.append(sepReal);
|
||||
|
@ -85,7 +85,7 @@ export class Array<T> implements ReadonlyArray<T>, Iterable<T> {
|
||||
if (idx >= this.actualLength) {
|
||||
throw new RangeError("Out of bounds")
|
||||
}
|
||||
this.buffer[idx] = val as Object
|
||||
this.buffer[idx] = val
|
||||
}
|
||||
|
||||
private $_set_unsafe(idx: int, val: T): void {
|
||||
|
@ -27,6 +27,8 @@ function main(): int {
|
||||
failures += check((): int => { return isArrayNullUndefined()}, "isArrayNullUndefined");
|
||||
failures += check((): int => { return push()}, "push");
|
||||
failures += check((): int => { return pushECMA()}, "pushECMA");
|
||||
failures += check((): int => { return setNull()}, "setNull");
|
||||
failures += check((): int => { return setCustomClass()}, "setCustomClass");
|
||||
failures += check((): int => { return toSplicedArg2()}, "toSplicedArg2");
|
||||
failures += check((): int => { return toSplicedArg1()}, "toSplicedArg1");
|
||||
return check(failures, "All tests run");
|
||||
@ -113,6 +115,23 @@ function pushECMA(): int {
|
||||
return success;
|
||||
}
|
||||
|
||||
function setNull(): int {
|
||||
let arr = new Array<string | null>(3);
|
||||
arr[1] = "abc"
|
||||
arr[2] = null;
|
||||
if (!(arr[2] instanceof null)) {
|
||||
return fail;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
function setCustomClass() : int {
|
||||
class A {}
|
||||
let arr = new Array<A>(1)
|
||||
arr[0] = new A()
|
||||
return success
|
||||
}
|
||||
|
||||
function toSplicedArg1(): int {
|
||||
let arr = new Array<Number>;
|
||||
for (let i: int = 0; i < dd.length; ++i) {
|
||||
|
@ -15,4 +15,6 @@
|
||||
|
||||
function main(): void {
|
||||
console.log(null, undefined, 11, "123", new Object())
|
||||
let arr = new Array<string | null | undefined>(3)
|
||||
console.log(arr)
|
||||
}
|
||||
|
@ -12,3 +12,4 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
null undefined 11 123 std.core.Object {}
|
||||
undefined,undefined,undefined
|
||||
|
Loading…
Reference in New Issue
Block a user