!2236 [ArkTS CTS] Add tests for 17.3 Indexable Types

Merge pull request !2236 from fotograf/cts-indexable-types
This commit is contained in:
openharmony_ci 2024-09-10 22:54:46 +00:00 committed by Gitee
commit bfe7ba1450
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
32 changed files with 3063 additions and 1 deletions

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Assignment context, variable, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
let d: {{c.to_type}}
function main(): int {
{%- for v in c['values'] %}
d = {{v.expr|safe}}
if (d != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Call context, constructor, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
class A {
f: {{c.to_type}}
constructor(p: {{c.to_type}}) { this.f = p }
}
function main(): int {
{%- for v in c['values'] %}
if (new A({{v.expr|safe}}).f != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Call context, function, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
function foo(p: {{c.to_type}}): {{c.to_type}} { return p }
function main(): int {
{%- for v in c['values'] %}
if (foo({{v.expr|safe}}) != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Call context, lambda, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
function main(): int {
{%- for v in c['values'] %}
if (((p: {{c.to_type}}): {{c.to_type}} => { return p })({{v.expr|safe}}) != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Call context, method, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
class A {
meth(p: {{c.to_type}}): {{c.to_type}} { return p }
}
function main(): int {
let a: A = new A()
{%- for v in c['values'] %}
if (a.meth({{v.expr|safe}}) != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Composite context, array element, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
function main(): int {
{%- for v in c['values'] %}
let d{{loop.index}}: {{c.to_type}}[] = [{{v.expr|safe}}]
d{{loop.index}} = []
d{{loop.index}} = [{{v.expr|safe}}]
if (d{{loop.index}}[0] != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Composite context, class field, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
{%- for v in c['values'] %}
class A{{loop.index}} { fld: {{c.to_type}} }
{%- endfor %}
function main(): int {
{%- for v in c['values'] %}
let d{{loop.index}}: A{{loop.index}} = { fld: {{v.expr|safe}} }
if (d{{loop.index}}.fld != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Composite context, interface field, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
{%- for v in c['values'] %}
interface J{{loop.index}} { fld: {{c.to_type}} }
{%- endfor %}
function main(): int {
{%- for v in c['values'] %}
let d{{loop.index}}: J{{loop.index}} = { fld: {{v.expr|safe}} }
if (d{{loop.index}}.fld != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -21,7 +21,7 @@ params: from {{c.from_type}} to {{c.to_type}}
{{c.defs}}
{%- for v in c['values'] %}
interface J{{loop.index}} { fld: {{c.to_type}} }
let s{{loop.index}}: {{c.from_type}} = {{v.expr|safe}}
let s{{loop.index}}: {{c.from_type}} = {{v.expr|safe}};
{%- endfor %}
function main(): int {

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Declaration context, constant declaration, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
function main(): int {
{%- for v in c['values'] %}
const d{{loop.index}}: {{c.to_type}} = {{v.expr|safe}}
if (d{{loop.index}} != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Declaration context, instance field declaration, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
{%- for v in c['values'] %}
class A{{loop.index}} {
public d: {{c.to_type}} = {{v.expr|safe}}
}
{%- endfor %}
function main(): int {
{%- for v in c['values'] %}
let a{{loop.index}}: A{{loop.index}} = new A{{loop.index}}()
if (a{{loop.index}}.d != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2024 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.
---
cases:
- from_type: byte
to_type: byte
values:
- { expr: 0 as byte, val: 0 }
- { expr: Byte.MIN_VALUE, val: -128 }
- { expr: Byte.MAX_VALUE, val: 127 }
- { expr: -128 as byte, val: -128 }
- { expr: 127 as byte, val: 127 }
- from_type: short
to_type: short
values:
- { expr: 0 as short, val: 0 }
- { expr: Short.MIN_VALUE, val: -32_768 }
- { expr: Short.MAX_VALUE, val: 32_767 }
- { expr: -32768 as short, val: -32_768 }
- { expr: 32767 as short, val: 32_767 }
- from_type: int
to_type: int
values:
- { expr: 0, val: 0 }
- { expr: Int.MIN_VALUE, val: -2147483648 }
- { expr: Int.MAX_VALUE, val: 2147483647 }
- { expr: -2147483648, val: -2147483648 }
- { expr: 2147483647, val: 2147483647 }
- from_type: long
to_type: long
values:
- { expr: 0 as long, val: 0 }
- { expr: Long.MIN_VALUE, val: -9223372036854775808 }
- { expr: Long.MAX_VALUE, val: 9223372036854775807 }
- { expr: -9223372036854775808 as long, val: -9223372036854775808 }
- { expr: 9223372036854775807 as long, val: 9223372036854775807 }
- from_type: float
to_type: float
values:
- { expr: +0.0f, val: +0.0f }
- { expr: -0.0f, val: -0.0f }
- { expr: 3.4028234663852886e38f, val: 3.4028234663852886e38f }
- { expr: 1.401298464324817e-45f, val: 1.401298464324817e-45f }
- { expr: -3.4028234663852886e38f, val: -3.4028234663852886e38f }
- { expr: -1.401298464324817e-45f, val: -1.401298464324817e-45f }
- from_type: double
to_type: double
values:
- { expr: +0.0, val: +0.0 }
- { expr: -0.0, val: -0.0 }
- { expr: 3.4028234663852886e38, val: 3.4028234663852886e38 }
- { expr: 1.401298464324817e-45, val: 1.401298464324817e-45 }
- { expr: -3.4028234663852886e38, val: -3.4028234663852886e38 }
- { expr: -1.401298464324817e-45, val: -1.401298464324817e-45 }
- from_type: char
to_type: char
values:
- { expr: "c'\\u0000'", val: 0 }
- { expr: "c'\\u0FFF'", val: 4095 }
- { expr: "c'\\uFFFF'", val: 65535 }

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 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.
*/
{%- for c in cases %}
/*---
desc: Declaration context, variable declaration, widening primitive conversion, implicit
params: from {{c.from_type}} to {{c.to_type}}
---*/
{{c.defs}}
function main(): int {
{%- for v in c['values'] %}
let d{{loop.index}}: {{c.to_type}} = {{v.expr|safe}}
if (d{{loop.index}} != {{v.val}}) {
return 1
}
{%- endfor %}
return 0
}
{%- endfor %}

View File

@ -0,0 +1,427 @@
# Copyright (c) 2024 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.
---
cases:
# positive case, read-write
- decl: |-
class A {
ind: string = ''
val: number
$_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
$_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a['a'] = 42.0
if (a['a'] != 42.0) return 1
a['a'] = 43.0
if (a['a'] != 43.0) return 1
# positive case, read-only, no $_set
- decl: |-
class A {
ind: string = ''
val: number
$_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
}
code: |-
let a: A = new A
if (!Number.isNaN(a['a'])) return 1
if (a[''] != 0.0) return 1
# negative case, read-only, no $_set
- tags: 'compile-only, negative'
decl: |-
class A {
ind: string = ''
val: number
$_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
}
code: |-
let a: A = new A
a['a'] = 42.0 // CTE
if (a['a'] != 42.0) return 1
# positive case, read-only, private $_set
- decl: |-
class A {
ind: string = ''
val: number
$_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
private $_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
if (!Number.isNaN(a['a'])) return 1
if (a[''] != 0.0) return 1
# negative case, read-only, private $_set
- tags: 'compile-only, negative'
decl: |-
class A {
ind: string = ''
val: number
$_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
private $_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a['a'] = 42.0 // CTE
if (a['a'] != 42.0) return 1
# positive case, write-only, no $_get
- decl: |-
class A {
ind: string = ''
val: number
$_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a['a'] = 42.0
if (a.val != 42.0) return 1
# negative case, write-only, no $_get
- tags: 'compile-only, negative'
decl: |-
class A {
ind: string = ''
val: number
$_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a['a'] = 42.0
if (a['a'] != 42.0) return 1 // CTE
# positive case, write-only, private $_get
- decl: |-
class A {
ind: string = ''
val: number
private $_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
$_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a['a'] = 42.0
if (a.val != 42.0) return 1
# negative case, write-only, private $_get
- tags: 'compile-only, negative'
decl: |-
class A {
ind: string = ''
val: number
private $_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
$_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a['a'] = 42.0
if (a['a'] != 42.0) return 1 // CTE
# negative cases, static is not allowed
- tags: 'compile-only, negative'
decl: |-
class A {
static $_get(i: string): number {
return 42.0
}
}
code: |-
let x = A['a'] // CTE
- tags: 'compile-only, negative'
decl: |-
class A {
static $_get(i: string): number {
return 42.0
}
}
code: |-
let a = new A
let x = a['a'] // CTE
- tags: 'compile-only, negative'
decl: |-
class A {
static $_set(i: string, v: number) {
return
}
}
code: |-
A['a'] = 42.0 // CTE
- tags: 'compile-only, negative'
decl: |-
class A {
static $_set(i: string, v: number) {
return
}
}
code: |-
let a = new A
a['a'] = 42.0 // CTE
# positive case, public read-write
- decl: |-
class A {
ind: string = ''
val: number
public $_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
public $_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
class B extends A {
push(ind: string, val: number) {
super[ind] = val
}
pull(ind: string): number {
return super[ind]
}
}
code: |-
let b = new B
b.push('a', 11.0)
if (b.pull('a') != 11.0) return 1
# positive case, protected read-write
- decl: |-
class A {
ind: string = ''
val: number
protected $_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
protected $_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
class B extends A {
push(ind: string, val: number) {
super[ind] = val
}
pull(ind: string): number {
return super[ind]
}
}
code: |-
let b = new B
b.push('a', 11.0)
if (b.pull('a') != 11.0) return 1
# positive case, private read-write
- decl: |-
class B {
ind: string = ''
val: number
private $_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
private $_set(i: string, v: number) {
this.ind = i
this.val = v
}
public push(ind: string, val: number) {
this[ind] = val
}
public pull(ind: string): number {
return this[ind]
}
}
code: |-
let b = new B
b.push('a', 11.0)
if (b.pull('a') != 11.0) return 1
# positive case, calling as ordinary methods
- decl: |-
class A {
ind: string = ''
val: number
$_get(i: string): number {
return i == this.ind ? this.val : Number.NaN
}
$_set(i: string, v: number) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a.$_set('a', 42.0)
if (a.$_get('a') != 42.0) return 1
a.$_set('a', 43.0)
if (a.$_get('a') != 43.0) return 1
# negative cases, async is not allowed
- tags: 'compile-only, negative'
decl: |-
class A {
async $_get(i: string): number { // CTE
return 42.0
}
}
code: |-
let a = new A
- tags: 'compile-only, negative'
decl: |-
class A {
async $_set(i: string, v: number) { // CTE
return
}
}
code: |-
let a = new A
# positive case, array value
- decl: |-
let empty: number[] = []
class A {
ind: string = ''
val: number[] = []
$_get(i: string): number[] {
return i == this.ind ? this.val : empty
}
$_set(i: string, v: number[]) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a['a'] = [42.0]
if (a['a'][0] != 42.0) return 1
a['a'] = [43.0, 44.0]
if (a['a'][1] != 44.0) return 1
- decl: |-
let empty: number[] = []
class A {
ind: int
val: number[] = []
$_get(i: int): number[] {
return i == this.ind ? this.val : empty
}
$_set(i: int, v: number[]) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
a[0] = [42.0]
if (a[0][0] != 42.0) return 1
a[1] = [43.0, 44.0]
if (a[1][1] != 44.0) return 1
- decl: |-
let empty: number[] = []
class A {
ind: int
val: number[] = []
$_get(i: int): number[] {
return i == this.ind ? this.val : empty
}
$_set(i: int, v: number[]) {
this.ind = i
this.val = v
}
}
code: |-
let a: A[] = [new A, new A]
a[0][0] = [42.0]
if (a[0][0][0] != 42.0) return 1
a[1][1] = [43.0, 44.0]
if (a[1][1][1] != 44.0) return 1
# positive case, another indexable class value
- decl: |-
let empty: number[] = []
class A {
ind: int
val: B = new B
$_get(i: int): B {
return i == this.ind ? this.val : new B
}
$_set(i: int, v: B) {
this.ind = i
this.val = v
}
}
class B {
ind: int
val: number[] = []
$_get(i: int): number[] {
return i == this.ind ? this.val : empty
}
$_set(i: int, v: number[]) {
this.ind = i
this.val = v
}
}
code: |-
let a: A = new A
let b1: B = new B
a[0] = b1
a[0][0] = [42.0]
if (a[0][0][0] != 42.0) return 1
let b2: B = new B
a[1] = b2
a[1][1] = [43.0, 44.0]
if (a[1][1][1] != 44.0) return 1

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 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.
*/
{% for c in cases %}
/*---
desc: >-
If a class or an interface declares one or two functions with names
$_get and $_set, and signatures (index: Type1): Type2 and
(index: Type1, value: Type2) respectively, then an indexing expression
can be applied to variables of such types
tags: [{{c.tags}}]
---*/
{{c.decl}}
function main(): int {
{{c.code|indent}}
return 0
}
{% endfor %}

View File

@ -0,0 +1,396 @@
# Copyright (c) 2024 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.
---
cases:
# byte type index
- ind_type: byte
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- ind_type: Byte
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
# short type index
- ind_type: short
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768 as short, val: '1.7' }
- { ind: 32767 as short, val: '1.8' }
- ind_type: Short
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768 as short, val: '1.7' }
- { ind: 32767 as short, val: '1.8' }
# int type index
- ind_type: int
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- ind_type: Int
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
# long type index
- ind_type: long
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- { ind: Long.MIN_VALUE, val: '1.5' }
- { ind: Long.MAX_VALUE, val: '1.5' }
- { ind: -9223372036854775808 as long, val: '1.5' }
- { ind: 9223372036854775807 as long, val: '1.5' }
- ind_type: Long
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- { ind: Long.MIN_VALUE, val: '1.5' }
- { ind: Long.MAX_VALUE, val: '1.5' }
- { ind: -9223372036854775808 as long, val: '1.5' }
- { ind: 9223372036854775807 as long, val: '1.5' }
# float and double index
- ind_type: number
val_type: number
values:
- { ind: '1.0f', val: '0.2' }
- { ind: '2.0f', val: '0.3' }
- { ind: '0.0f', val: '0.1' }
- { ind: '1.0', val: '0.5' }
- { ind: '2.0', val: '0.6' }
- { ind: '0.0', val: '0.4' }
- { ind: '-1.0f', val: '0.8' }
- { ind: '-2.0f', val: '0.9' }
- { ind: '-0.0f', val: '0.7' }
- { ind: '-1.0', val: '1.1' }
- { ind: '-2.0', val: '1.2' }
- { ind: '-0.0', val: '1.0' }
- ind_type: Number
val_type: number
values:
- { ind: '1.0f', val: '0.2' }
- { ind: '2.0f', val: '0.3' }
- { ind: '0.0f', val: '0.1' }
- { ind: '1.0', val: '0.5' }
- { ind: '2.0', val: '0.6' }
- { ind: '0.0', val: '0.4' }
- { ind: '-1.0f', val: '0.8' }
- { ind: '-2.0f', val: '0.9' }
- { ind: '-0.0f', val: '0.7' }
- { ind: '-1.0', val: '1.1' }
- { ind: '-2.0', val: '1.2' }
- { ind: '-0.0', val: '1.0' }
# float and double index with fraction
- ind_type: number
val_type: number
values:
- { ind: '0.1f', val: '0.1' }
- { ind: '-0.2f', val: '0.2' }
- { ind: '1.3f', val: '0.3' }
- { ind: '-1.4f', val: '0.4' }
- { ind: '2.5f', val: '0.5' }
- { ind: '-2.6f', val: '0.6' }
- { ind: '0.7', val: '0.7' }
- { ind: '-0.8', val: '0.8' }
- { ind: '1.9', val: '0.9' }
- { ind: '-1.1', val: '1.0' }
- { ind: '2.2', val: '1.1' }
- { ind: '-2.3', val: '1.2' }
- ind_type: Number
val_type: number
values:
- { ind: '0.1f', val: '0.1' }
- { ind: '-0.2f', val: '0.2' }
- { ind: '1.3f', val: '0.3' }
- { ind: '-1.4f', val: '0.4' }
- { ind: '2.5f', val: '0.5' }
- { ind: '-2.6f', val: '0.6' }
- { ind: '0.7', val: '0.7' }
- { ind: '-0.8', val: '0.8' }
- { ind: '1.9', val: '0.9' }
- { ind: '-1.1', val: '1.0' }
- { ind: '2.2', val: '1.1' }
- { ind: '-2.3', val: '1.2' }
# float and double index special cases
- ind_type: number
val_type: number
values:
- { ind: Float.POSITIVE_INFINITY, val: '0.3' }
- { ind: Float.NEGATIVE_INFINITY, val: '0.4' }
- { ind: Double.POSITIVE_INFINITY, val: '0.5' }
- { ind: Double.NEGATIVE_INFINITY, val: '0.6' }
- ind_type: Number
val_type: number
values:
- { ind: Float.POSITIVE_INFINITY, val: '0.3' }
- { ind: Float.NEGATIVE_INFINITY, val: '0.4' }
- { ind: Double.POSITIVE_INFINITY, val: '0.5' }
- { ind: Double.NEGATIVE_INFINITY, val: '0.6' }
# char type index
- ind_type: char
val_type: char
values:
- { ind: Char.MAX_VALUE, val: "c'\\uF002'" }
- { ind: Char.MIN_VALUE, val: "c'\\uF001'" }
- { ind: "c'\\uFFFF'", val: "c'\\uF004'" }
- { ind: "c'\\u0000'", val: "c'\\uF003'" }
- ind_type: Char
val_type: char
values:
- { ind: Char.MAX_VALUE, val: "c'\\uF002'" }
- { ind: Char.MIN_VALUE, val: "c'\\uF001'" }
- { ind: "c'\\uFFFF'", val: "c'\\uF004'" }
- { ind: "c'\\u0000'", val: "c'\\uF003'" }
# number index
- ind_type: number
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
# string type index
- ind_type: string
val_type: number
values:
- { ind: "''", val: Double.MAX_SAFE_INTEGER }
- { ind: "'\\u0000'", val: Double.MIN_SAFE_INTEGER }
- { ind: "' '", val: '1.0' }
- { ind: "'0.1'", val: '2.0' }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: '3.5'
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: '2.5e2'
- ind_type: String
val_type: number
values:
- { ind: "''", val: Double.MAX_SAFE_INTEGER }
- { ind: "'\\u0000'", val: Double.MIN_SAFE_INTEGER }
- { ind: "' '", val: '1.0' }
- { ind: "'0.1'", val: '2.0' }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: '3.5'
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: '2.5e2'
# string type index, string type value
- ind_type: string
val_type: string
values:
- { ind: "''", val: "''" }
- { ind: "'\\u0000'", val: "'\\u0000'" }
- { ind: "' '", val: "' '" }
- { ind: "'0.1'", val: "'0.0'" }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: "'==='"
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
- ind_type: String
val_type: string
values:
- { ind: "''", val: "''" }
- { ind: "'\\u0000'", val: "'\\u0000'" }
- { ind: "' '", val: "' '" }
- { ind: "'0.1'", val: "'0.0'" }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: "'==='"
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
# boolean type index
- decl: |-
const t: boolean = true
const f: boolean = false
ind_type: boolean
val_type: number
values:
- { ind: 'true', val: '1.5' }
- { ind: 'false', val: '1.6' }
- { ind: 't', val: '1.7' }
- { ind: 'f', val: '1.8' }
- decl: |-
const t: Boolean = new Boolean(true)
const f: Boolean = new Boolean(false)
ind_type: Boolean
val_type: number
values:
- { ind: 'true', val: '1.5' }
- { ind: 'false', val: '1.6' }
- { ind: 't', val: '1.7' }
- { ind: 'f', val: '1.8' }
# custom class index
- decl: |-
class Z {}
let a1: Z = new Z()
let a2: Z = new Z()
ind_type: Z
val_type: number
values:
- { ind: a1, val: '1.5' }
- { ind: a2, val: '1.6' }
# union type index
- ind_type: string|number|null
val_type: number
values:
- { ind: '1.0', val: '1.5' }
- { ind: "'abc'", val: '1.6' }
- { ind: '2.0', val: '1.7' }
- { ind: "'def'", val: '1.8' }
# tuple type index
- decl: |-
type TT = [string, number]
let t1: TT = ['a', 1.0]
let t2: TT = ['b', 2.0]
let t3: TT = ['c', 3.0]
ind_type: TT
val_type: number
values:
- { ind: t1, val: '1.5' }
- { ind: t2, val: '1.6' }
- { ind: t3, val: '1.7' }
# enum type index
- decl: |-
enum Color { Red, Green, Blue }
ind_type: 'Color'
val_type: number
values:
- { ind: "Color.Green", val: '1.5' }
- { ind: "Color.Red", val: '1.6' }
- { ind: "Color.Blue", val: '1.7' }
# array type index
- decl: |-
let a1: number[] = [1.0, 1.0]
let a2: number[] = [2.0, 2.0]
ind_type: 'number[]'
val_type: number
values:
- { ind: "a1", val: '1.5' }
- { ind: "a2", val: '1.6' }
# object type index
- decl: |-
let a1: number[] = [1.0, 1.0]
let a2: string = 'abc'
let a3: Error = new Error()
ind_type: Object
val_type: number
values:
- { ind: "a1", val: '1.5' }
- { ind: "a2", val: '1.6' }
- { ind: "a3", val: '1.7' }
# parameterized custom class index
- decl: |-
class Z<T> {}
let a1: Z<Error> = new Z<Error>()
let a2: Z<Error> = new Z<Error>()
ind_type: Z<Error>
val_type: number
values:
- { ind: a1, val: '1.5' }
- { ind: a2, val: '1.6' }

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2024 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.
*/
{% for c in cases %}
/*---
desc: >-
If a class or an interface declares one or two functions with names
$_get and $_set, and signatures (index: Type1): Type2 and
(index: Type1, value: Type2) respectively, then an indexing expression
can be applied to variables of such types
tags: [{{c.tags}}]
---*/
{{c.decl}}
abstract class Base<T, U> {
ind: T
val: U
abstract $_get(i: T): U|undefined;
$_set(i: T, v: U) {
this.ind = i
this.val = v
}
}
class A<T, U> extends Base<T, U> {
$_get(i: T): U|undefined {
return i == this.ind ? this.val : undefined
}
}
function main(): int {
let a: A<{{c.ind_type}}, {{c.val_type}}> = new A<{{c.ind_type}}, {{c.val_type}}>
{% for t in c['values'] %}
if (a[{{t.ind}}] != undefined) return 1
a[{{t.ind}}] = {{t.val}}
if (a[{{t.ind}}] != {{t.val}}) return 1
{% endfor %}
return 0;
}
{% endfor %}

View File

@ -0,0 +1,396 @@
# Copyright (c) 2024 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.
---
cases:
# byte type index
- ind_type: byte
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- ind_type: Byte
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
# short type index
- ind_type: short
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768 as short, val: '1.7' }
- { ind: 32767 as short, val: '1.8' }
- ind_type: Short
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768 as short, val: '1.7' }
- { ind: 32767 as short, val: '1.8' }
# int type index
- ind_type: int
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- ind_type: Int
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
# long type index
- ind_type: long
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- { ind: Long.MIN_VALUE, val: '1.5' }
- { ind: Long.MAX_VALUE, val: '1.5' }
- { ind: -9223372036854775808 as long, val: '1.5' }
- { ind: 9223372036854775807 as long, val: '1.5' }
- ind_type: Long
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- { ind: Long.MIN_VALUE, val: '1.5' }
- { ind: Long.MAX_VALUE, val: '1.5' }
- { ind: -9223372036854775808 as long, val: '1.5' }
- { ind: 9223372036854775807 as long, val: '1.5' }
# float and double index
- ind_type: number
val_type: number
values:
- { ind: '1.0f', val: '0.2' }
- { ind: '2.0f', val: '0.3' }
- { ind: '0.0f', val: '0.1' }
- { ind: '1.0', val: '0.5' }
- { ind: '2.0', val: '0.6' }
- { ind: '0.0', val: '0.4' }
- { ind: '-1.0f', val: '0.8' }
- { ind: '-2.0f', val: '0.9' }
- { ind: '-0.0f', val: '0.7' }
- { ind: '-1.0', val: '1.1' }
- { ind: '-2.0', val: '1.2' }
- { ind: '-0.0', val: '1.0' }
- ind_type: Number
val_type: number
values:
- { ind: '1.0f', val: '0.2' }
- { ind: '2.0f', val: '0.3' }
- { ind: '0.0f', val: '0.1' }
- { ind: '1.0', val: '0.5' }
- { ind: '2.0', val: '0.6' }
- { ind: '0.0', val: '0.4' }
- { ind: '-1.0f', val: '0.8' }
- { ind: '-2.0f', val: '0.9' }
- { ind: '-0.0f', val: '0.7' }
- { ind: '-1.0', val: '1.1' }
- { ind: '-2.0', val: '1.2' }
- { ind: '-0.0', val: '1.0' }
# float and double index with fraction
- ind_type: number
val_type: number
values:
- { ind: '0.1f', val: '0.1' }
- { ind: '-0.2f', val: '0.2' }
- { ind: '1.3f', val: '0.3' }
- { ind: '-1.4f', val: '0.4' }
- { ind: '2.5f', val: '0.5' }
- { ind: '-2.6f', val: '0.6' }
- { ind: '0.7', val: '0.7' }
- { ind: '-0.8', val: '0.8' }
- { ind: '1.9', val: '0.9' }
- { ind: '-1.1', val: '1.0' }
- { ind: '2.2', val: '1.1' }
- { ind: '-2.3', val: '1.2' }
- ind_type: Number
val_type: number
values:
- { ind: '0.1f', val: '0.1' }
- { ind: '-0.2f', val: '0.2' }
- { ind: '1.3f', val: '0.3' }
- { ind: '-1.4f', val: '0.4' }
- { ind: '2.5f', val: '0.5' }
- { ind: '-2.6f', val: '0.6' }
- { ind: '0.7', val: '0.7' }
- { ind: '-0.8', val: '0.8' }
- { ind: '1.9', val: '0.9' }
- { ind: '-1.1', val: '1.0' }
- { ind: '2.2', val: '1.1' }
- { ind: '-2.3', val: '1.2' }
# float and double index special cases
- ind_type: number
val_type: number
values:
- { ind: Float.POSITIVE_INFINITY, val: '0.3' }
- { ind: Float.NEGATIVE_INFINITY, val: '0.4' }
- { ind: Double.POSITIVE_INFINITY, val: '0.5' }
- { ind: Double.NEGATIVE_INFINITY, val: '0.6' }
- ind_type: Number
val_type: number
values:
- { ind: Float.POSITIVE_INFINITY, val: '0.3' }
- { ind: Float.NEGATIVE_INFINITY, val: '0.4' }
- { ind: Double.POSITIVE_INFINITY, val: '0.5' }
- { ind: Double.NEGATIVE_INFINITY, val: '0.6' }
# char type index
- ind_type: char
val_type: char
values:
- { ind: Char.MAX_VALUE, val: "c'\\uF002'" }
- { ind: Char.MIN_VALUE, val: "c'\\uF001'" }
- { ind: "c'\\uFFFF'", val: "c'\\uF004'" }
- { ind: "c'\\u0000'", val: "c'\\uF003'" }
- ind_type: Char
val_type: char
values:
- { ind: Char.MAX_VALUE, val: "c'\\uF002'" }
- { ind: Char.MIN_VALUE, val: "c'\\uF001'" }
- { ind: "c'\\uFFFF'", val: "c'\\uF004'" }
- { ind: "c'\\u0000'", val: "c'\\uF003'" }
# number index
- ind_type: number
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
# string type index
- ind_type: string
val_type: number
values:
- { ind: "''", val: Double.MAX_SAFE_INTEGER }
- { ind: "'\\u0000'", val: Double.MIN_SAFE_INTEGER }
- { ind: "' '", val: '1.0' }
- { ind: "'0.1'", val: '2.0' }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: '3.5'
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: '2.5e2'
- ind_type: String
val_type: number
values:
- { ind: "''", val: Double.MAX_SAFE_INTEGER }
- { ind: "'\\u0000'", val: Double.MIN_SAFE_INTEGER }
- { ind: "' '", val: '1.0' }
- { ind: "'0.1'", val: '2.0' }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: '3.5'
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: '2.5e2'
# string type index, string type value
- ind_type: string
val_type: string
values:
- { ind: "''", val: "''" }
- { ind: "'\\u0000'", val: "'\\u0000'" }
- { ind: "' '", val: "' '" }
- { ind: "'0.1'", val: "'0.0'" }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: "'==='"
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
- ind_type: String
val_type: string
values:
- { ind: "''", val: "''" }
- { ind: "'\\u0000'", val: "'\\u0000'" }
- { ind: "' '", val: "' '" }
- { ind: "'0.1'", val: "'0.0'" }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: "'==='"
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
# boolean type index
- decl: |-
const t: boolean = true
const f: boolean = false
ind_type: boolean
val_type: number
values:
- { ind: 'true', val: '1.5' }
- { ind: 'false', val: '1.6' }
- { ind: 't', val: '1.7' }
- { ind: 'f', val: '1.8' }
- decl: |-
const t: Boolean = new Boolean(true)
const f: Boolean = new Boolean(false)
ind_type: Boolean
val_type: number
values:
- { ind: 'true', val: '1.5' }
- { ind: 'false', val: '1.6' }
- { ind: 't', val: '1.7' }
- { ind: 'f', val: '1.8' }
# custom class index
- decl: |-
class Z {}
let a1: Z = new Z()
let a2: Z = new Z()
ind_type: Z
val_type: number
values:
- { ind: a1, val: '1.5' }
- { ind: a2, val: '1.6' }
# union type index
- ind_type: string|number|null
val_type: number
values:
- { ind: '1.0', val: '1.5' }
- { ind: "'abc'", val: '1.6' }
- { ind: '2.0', val: '1.7' }
- { ind: "'def'", val: '1.8' }
# tuple type index
- decl: |-
type TT = [string, number]
let t1: TT = ['a', 1.0]
let t2: TT = ['b', 2.0]
let t3: TT = ['c', 3.0]
ind_type: TT
val_type: number
values:
- { ind: t1, val: '1.5' }
- { ind: t2, val: '1.6' }
- { ind: t3, val: '1.7' }
# enum type index
- decl: |-
enum Color { Red, Green, Blue }
ind_type: 'Color'
val_type: number
values:
- { ind: "Color.Green", val: '1.5' }
- { ind: "Color.Red", val: '1.6' }
- { ind: "Color.Blue", val: '1.7' }
# array type index
- decl: |-
let a1: number[] = [1.0, 1.0]
let a2: number[] = [2.0, 2.0]
ind_type: 'number[]'
val_type: number
values:
- { ind: "a1", val: '1.5' }
- { ind: "a2", val: '1.6' }
# object type index
- decl: |-
let a1: number[] = [1.0, 1.0]
let a2: string = 'abc'
let a3: Error = new Error()
ind_type: Object
val_type: number
values:
- { ind: "a1", val: '1.5' }
- { ind: "a2", val: '1.6' }
- { ind: "a3", val: '1.7' }
# parameterized custom class index
- decl: |-
class Z<T> {}
let a1: Z<Error> = new Z<Error>()
let a2: Z<Error> = new Z<Error>()
ind_type: Z<Error>
val_type: number
values:
- { ind: a1, val: '1.5' }
- { ind: a2, val: '1.6' }

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 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.
*/
{% for c in cases %}
/*---
desc: >-
If a class or an interface declares one or two functions with names
$_get and $_set, and signatures (index: Type1): Type2 and
(index: Type1, value: Type2) respectively, then an indexing expression
can be applied to variables of such types
tags: [{{c.tags}}]
---*/
{{c.decl}}
let m: Map<{{c.ind_type}}, {{c.val_type}}|undefined> = new Map<{{c.ind_type}}, {{c.val_type}}|undefined>
interface I {
$_set(i: {{c.ind_type}}, v: {{c.val_type}}|undefined) {
m.set(i, v)
}
}
class A implements I {
$_get(i: {{c.ind_type}}): {{c.val_type}}|undefined {
return m.get(i)
}
}
function foo(): A {
return new A()
}
{%- for t in c['values'] %}
let ind{{loop.index}} = (): {{c.ind_type}} => {{t.ind}}
{%- endfor %}
function main(): int {
let a: A
{% for t in c['values'] %}
(a = foo())[ind{{loop.index}}()] = {{t.val}}
if (new A()[ind{{loop.index}}()] != {{t.val}}) return 1
a[ind{{loop.index}}()] = undefined;
{% endfor %}
return 0
}
{% endfor %}

View File

@ -0,0 +1,396 @@
# Copyright (c) 2024 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.
---
cases:
# byte type index
- ind_type: byte
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- ind_type: Byte
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
# short type index
- ind_type: short
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768 as short, val: '1.7' }
- { ind: 32767 as short, val: '1.8' }
- ind_type: Short
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128 as byte, val: '1.7' }
- { ind: 127 as byte, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768 as short, val: '1.7' }
- { ind: 32767 as short, val: '1.8' }
# int type index
- ind_type: int
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- ind_type: Int
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
# long type index
- ind_type: long
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- { ind: Long.MIN_VALUE, val: '1.5' }
- { ind: Long.MAX_VALUE, val: '1.5' }
- { ind: -9223372036854775808 as long, val: '1.5' }
- { ind: 9223372036854775807 as long, val: '1.5' }
- ind_type: Long
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
- { ind: Long.MIN_VALUE, val: '1.5' }
- { ind: Long.MAX_VALUE, val: '1.5' }
- { ind: -9223372036854775808 as long, val: '1.5' }
- { ind: 9223372036854775807 as long, val: '1.5' }
# float and double index
- ind_type: number
val_type: number
values:
- { ind: '1.0f', val: '0.2' }
- { ind: '2.0f', val: '0.3' }
- { ind: '0.0f', val: '0.1' }
- { ind: '1.0', val: '0.5' }
- { ind: '2.0', val: '0.6' }
- { ind: '0.0', val: '0.4' }
- { ind: '-1.0f', val: '0.8' }
- { ind: '-2.0f', val: '0.9' }
- { ind: '-0.0f', val: '0.7' }
- { ind: '-1.0', val: '1.1' }
- { ind: '-2.0', val: '1.2' }
- { ind: '-0.0', val: '1.0' }
- ind_type: Number
val_type: number
values:
- { ind: '1.0f', val: '0.2' }
- { ind: '2.0f', val: '0.3' }
- { ind: '0.0f', val: '0.1' }
- { ind: '1.0', val: '0.5' }
- { ind: '2.0', val: '0.6' }
- { ind: '0.0', val: '0.4' }
- { ind: '-1.0f', val: '0.8' }
- { ind: '-2.0f', val: '0.9' }
- { ind: '-0.0f', val: '0.7' }
- { ind: '-1.0', val: '1.1' }
- { ind: '-2.0', val: '1.2' }
- { ind: '-0.0', val: '1.0' }
# float and double index with fraction
- ind_type: number
val_type: number
values:
- { ind: '0.1f', val: '0.1' }
- { ind: '-0.2f', val: '0.2' }
- { ind: '1.3f', val: '0.3' }
- { ind: '-1.4f', val: '0.4' }
- { ind: '2.5f', val: '0.5' }
- { ind: '-2.6f', val: '0.6' }
- { ind: '0.7', val: '0.7' }
- { ind: '-0.8', val: '0.8' }
- { ind: '1.9', val: '0.9' }
- { ind: '-1.1', val: '1.0' }
- { ind: '2.2', val: '1.1' }
- { ind: '-2.3', val: '1.2' }
- ind_type: Number
val_type: number
values:
- { ind: '0.1f', val: '0.1' }
- { ind: '-0.2f', val: '0.2' }
- { ind: '1.3f', val: '0.3' }
- { ind: '-1.4f', val: '0.4' }
- { ind: '2.5f', val: '0.5' }
- { ind: '-2.6f', val: '0.6' }
- { ind: '0.7', val: '0.7' }
- { ind: '-0.8', val: '0.8' }
- { ind: '1.9', val: '0.9' }
- { ind: '-1.1', val: '1.0' }
- { ind: '2.2', val: '1.1' }
- { ind: '-2.3', val: '1.2' }
# float and double index special cases
- ind_type: number
val_type: number
values:
- { ind: Float.POSITIVE_INFINITY, val: '0.3' }
- { ind: Float.NEGATIVE_INFINITY, val: '0.4' }
- { ind: Double.POSITIVE_INFINITY, val: '0.5' }
- { ind: Double.NEGATIVE_INFINITY, val: '0.6' }
- ind_type: Number
val_type: number
values:
- { ind: Float.POSITIVE_INFINITY, val: '0.3' }
- { ind: Float.NEGATIVE_INFINITY, val: '0.4' }
- { ind: Double.POSITIVE_INFINITY, val: '0.5' }
- { ind: Double.NEGATIVE_INFINITY, val: '0.6' }
# char type index
- ind_type: char
val_type: char
values:
- { ind: Char.MAX_VALUE, val: "c'\\uF002'" }
- { ind: Char.MIN_VALUE, val: "c'\\uF001'" }
- { ind: "c'\\uFFFF'", val: "c'\\uF004'" }
- { ind: "c'\\u0000'", val: "c'\\uF003'" }
- ind_type: Char
val_type: char
values:
- { ind: Char.MAX_VALUE, val: "c'\\uF002'" }
- { ind: Char.MIN_VALUE, val: "c'\\uF001'" }
- { ind: "c'\\uFFFF'", val: "c'\\uF004'" }
- { ind: "c'\\u0000'", val: "c'\\uF003'" }
# number index
- ind_type: number
val_type: number
values:
- { ind: Byte.MIN_VALUE, val: '1.5' }
- { ind: Byte.MAX_VALUE, val: '1.6' }
- { ind: -128, val: '1.7' }
- { ind: 127, val: '1.8' }
- { ind: Short.MIN_VALUE, val: '1.5' }
- { ind: Short.MAX_VALUE, val: '1.6' }
- { ind: -32768, val: '1.7' }
- { ind: 32767, val: '1.8' }
- { ind: Int.MIN_VALUE, val: '1.5' }
- { ind: Int.MAX_VALUE, val: '1.6' }
- { ind: -2147483648, val: '1.7' }
- { ind: 2147483647, val: '1.8' }
# string type index
- ind_type: string
val_type: number
values:
- { ind: "''", val: Double.MAX_SAFE_INTEGER }
- { ind: "'\\u0000'", val: Double.MIN_SAFE_INTEGER }
- { ind: "' '", val: '1.0' }
- { ind: "'0.1'", val: '2.0' }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: '3.5'
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: '2.5e2'
- ind_type: String
val_type: number
values:
- { ind: "''", val: Double.MAX_SAFE_INTEGER }
- { ind: "'\\u0000'", val: Double.MIN_SAFE_INTEGER }
- { ind: "' '", val: '1.0' }
- { ind: "'0.1'", val: '2.0' }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: '3.5'
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: '2.5e2'
# string type index, string type value
- ind_type: string
val_type: string
values:
- { ind: "''", val: "''" }
- { ind: "'\\u0000'", val: "'\\u0000'" }
- { ind: "' '", val: "' '" }
- { ind: "'0.1'", val: "'0.0'" }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: "'==='"
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
- ind_type: String
val_type: string
values:
- { ind: "''", val: "''" }
- { ind: "'\\u0000'", val: "'\\u0000'" }
- { ind: "' '", val: "' '" }
- { ind: "'0.1'", val: "'0.0'" }
- ind: "'uNWg4C5uvdoWVQpBtVa4qPYNRNrveJbGd8FqhQoNRKN65lMUBRZ3xz41YETWnqelAuhLPO90zCKUJ6h4TZnlScRPol6sqG624yJjwyGiIFT3Q3egI6xpFQRHjSd5HKG5kpQiBN35XOy3X9iRG6Fa6yXChLe3QDhFOtErB'"
val: "'==='"
- ind: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
val: "'ZKF4iFmBMyAibBDOotckevShohdFohEalJro6X5Jw3vwthDs5yjP35jBHpbEWctRB4RoMPxxwhalah2xOGPcZ3DLrAmuF7Y43CPhiN9ClzX4C4xPfcWjzZwrUZunGNIEUQHrdjv7yfHg4D0AjNJiU9CZOwCy9I7ztV2IXW94FPFBzDgCgUEEpw5LiWKoSztRwze0M3D7g34GknAT3raBprQ6FDcOITvql0URYI1MlMpBCo8tb7fZA9sh4hiB3l6ViTd'"
# boolean type index
- decl: |-
const t: boolean = true
const f: boolean = false
ind_type: boolean
val_type: number
values:
- { ind: 'true', val: '1.5' }
- { ind: 'false', val: '1.6' }
- { ind: 't', val: '1.7' }
- { ind: 'f', val: '1.8' }
- decl: |-
const t: Boolean = new Boolean(true)
const f: Boolean = new Boolean(false)
ind_type: Boolean
val_type: number
values:
- { ind: 'true', val: '1.5' }
- { ind: 'false', val: '1.6' }
- { ind: 't', val: '1.7' }
- { ind: 'f', val: '1.8' }
# custom class index
- decl: |-
class Z {}
let a1: Z = new Z()
let a2: Z = new Z()
ind_type: Z
val_type: number
values:
- { ind: a1, val: '1.5' }
- { ind: a2, val: '1.6' }
# union type index
- ind_type: string|number|null
val_type: number
values:
- { ind: '1.0', val: '1.5' }
- { ind: "'abc'", val: '1.6' }
- { ind: '2.0', val: '1.7' }
- { ind: "'def'", val: '1.8' }
# tuple type index
- decl: |-
type TT = [string, number]
let t1: TT = ['a', 1.0]
let t2: TT = ['b', 2.0]
let t3: TT = ['c', 3.0]
ind_type: TT
val_type: number
values:
- { ind: t1, val: '1.5' }
- { ind: t2, val: '1.6' }
- { ind: t3, val: '1.7' }
# enum type index
- decl: |-
enum Color { Red, Green, Blue }
ind_type: 'Color'
val_type: number
values:
- { ind: "Color.Green", val: '1.5' }
- { ind: "Color.Red", val: '1.6' }
- { ind: "Color.Blue", val: '1.7' }
# array type index
- decl: |-
let a1: number[] = [1.0, 1.0]
let a2: number[] = [2.0, 2.0]
ind_type: 'number[]'
val_type: number
values:
- { ind: "a1", val: '1.5' }
- { ind: "a2", val: '1.6' }
# object type index
- decl: |-
let a1: number[] = [1.0, 1.0]
let a2: string = 'abc'
let a3: Error = new Error()
ind_type: Object
val_type: number
values:
- { ind: "a1", val: '1.5' }
- { ind: "a2", val: '1.6' }
- { ind: "a3", val: '1.7' }
# parameterized custom class index
- decl: |-
class Z<T> {}
let a1: Z<Error> = new Z<Error>()
let a2: Z<Error> = new Z<Error>()
ind_type: Z<Error>
val_type: number
values:
- { ind: a1, val: '1.5' }
- { ind: a2, val: '1.6' }

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 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.
*/
{% for c in cases %}
/*---
desc: >-
If a class or an interface declares one or two functions with names
$_get and $_set, and signatures (index: Type1): Type2 and
(index: Type1, value: Type2) respectively, then an indexing expression
can be applied to variables of such types
tags: [{{c.tags}}]
---*/
{{c.decl}}
interface I {
$_get(i: {{c.ind_type}}|undefined): {{c.val_type}}|undefined;
$_set(i: {{c.ind_type}}, v: {{c.val_type}}): void;
}
class A implements I {
ind: {{c.ind_type}}|undefined
val: {{c.val_type}}|undefined
$_get(i: {{c.ind_type}}|undefined): {{c.val_type}}|undefined {
return i == this.ind ? this.val : undefined
}
$_set(i: {{c.ind_type}}, v: {{c.val_type}}) {
this.ind = i
this.val = v
}
}
function main(): int {
let i: I = new A
{% for t in c['values'] %}
if (i[{{t.ind}}] != undefined) return 1
i[{{t.ind}}] = {{t.val}}
if (i[{{t.ind}}] != {{t.val}}) return 1
{% endfor %}
return 0;
}
{% endfor %}

View File

@ -1449,6 +1449,13 @@
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf_7.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf_8.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf_9.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf-ident_0.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf-ident_1.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf-ident_2.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf-ident_3.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf-ident_4.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf-ident_5.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/comp_obj/comp-intf-ident_6.sts
06.contexts_and_conversions/05.implicit_conversions/04.boxing_conversion/comp_obj/comp-intf-nan_0.sts
06.contexts_and_conversions/05.implicit_conversions/04.boxing_conversion/comp_obj/comp-intf-nan_1.sts
06.contexts_and_conversions/05.implicit_conversions/04.boxing_conversion/comp_obj/comp-intf-nan_2.sts
@ -2066,6 +2073,36 @@
15.semantic_rules/07.overloading_and_overriding/03.overloading_for_functions/function_import_neg_8.sts
15.semantic_rules/07.overloading_and_overriding/03.overloading_for_functions/function_import_neg_9.sts
# 18550 es2panda aborts on implicit number conversion
17.experimental_features/03.indexable_types/ind_interface_4.sts
17.experimental_features/03.indexable_types/ind_interface_5.sts
17.experimental_features/03.indexable_types/ind_interface_6.sts
17.experimental_features/03.indexable_types/ind_interface_7.sts
17.experimental_features/03.indexable_types/ind_class_4.sts
17.experimental_features/03.indexable_types/ind_class_5.sts
17.experimental_features/03.indexable_types/ind_class_6.sts
17.experimental_features/03.indexable_types/ind_class_7.sts
17.experimental_features/03.indexable_types/ind_interface_12.sts
17.experimental_features/03.indexable_types/ind_interface_13.sts
17.experimental_features/03.indexable_types/ind_class_12.sts
17.experimental_features/03.indexable_types/ind_class_13.sts
17.experimental_features/03.indexable_types/ind_interface_16.sts
17.experimental_features/03.indexable_types/ind_class_16.sts
17.experimental_features/03.indexable_types/ind_class_26.sts
17.experimental_features/03.indexable_types/ind_expr_26.sts
# 18553 Int.MIN_VALUE is interpreted as long
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/call_cons/call-cons-ident_2.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/call_func/call-func-ident_2.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/call_lmbd/call-lmbd-ident_2.sts
06.contexts_and_conversions/05.implicit_conversions/02.widening_primitive_conversions/call_meth/call-meth-ident_2.sts
# 18589 es2panda segfault with protected $_get and $_set
17.experimental_features/03.indexable_types/cte_14.sts
# 18590 Cannot use private $_get and $_set
17.experimental_features/03.indexable_types/cte_15.sts
# es2panda: #17635: Smart cast problem
04.names_declarations_and_scopes/06.type_declarations/01.type_alias_declaration/alias_gen_4.sts