From 8445f57d2a732125bb74962a6fe0a09c743c6afc Mon Sep 17 00:00:00 2001 From: fotograf Date: Thu, 19 Oct 2023 14:27:23 +0000 Subject: [PATCH 1/4] Added tests for 3.7.5 Character Types and Operations Change-Id: I60fbc3f73104579e410da37758bb7a5620316842 Signed-off-by: fotograf --- .../addition/add_arr_ref.ets | 31 ++++ .../addition/add_arr_ref.params.yaml | 48 +++++++ .../addition/add_arr_val.ets | 31 ++++ .../addition/add_arr_val.params.yaml | 48 +++++++ .../addition/add_func_ref.ets | 32 +++++ .../addition/add_func_ref.params.yaml | 48 +++++++ .../addition/add_func_val.ets | 32 +++++ .../addition/add_func_val.params.yaml | 48 +++++++ .../ch_n.ets | 25 ++++ .../ch_n.params.yaml | 27 ++++ .../comparison/cmp_ref.ets | 30 ++++ .../comparison/cmp_ref.params.yaml | 53 +++++++ .../comparison/cmp_val.ets | 30 ++++ .../comparison/cmp_val.params.yaml | 53 +++++++ .../concat/conc2.ets | 25 ++++ .../concat/conc2.params.yaml | 39 +++++ .../concat/conc_ref.ets | 38 +++++ .../concat/conc_ref.params.yaml | 38 +++++ .../concat/conc_val.ets | 38 +++++ .../concat/conc_val.params.yaml | 38 +++++ .../conditional/cond_exp_val.ets | 30 ++++ .../conditional/cond_exp_val.params.yaml | 34 +++++ .../conditional/cond_fld_val.ets | 32 +++++ .../conditional/cond_fld_val.params.yaml | 28 ++++ .../conditional/cond_func_ref.ets | 32 +++++ .../conditional/cond_func_ref.params.yaml | 38 +++++ .../conditional/cond_func_val.ets | 32 +++++ .../conditional/cond_func_val.params.yaml | 38 +++++ .../decrement/dec_arr_ref.ets | 34 +++++ .../decrement/dec_arr_ref.params.yaml | 33 +++++ .../decrement/dec_arr_val.ets | 34 +++++ .../decrement/dec_arr_val.params.yaml | 33 +++++ .../decrement/dec_func_ref.ets | 36 +++++ .../decrement/dec_func_ref.params.yaml | 69 +++++++++ .../decrement/dec_func_val.ets | 36 +++++ .../decrement/dec_func_val.params.yaml | 69 +++++++++ .../increment/inc_arr_ref.ets | 34 +++++ .../increment/inc_arr_ref.params.yaml | 37 +++++ .../increment/inc_arr_val.ets | 34 +++++ .../increment/inc_arr_val.params.yaml | 37 +++++ .../increment/inc_func_ref.ets | 36 +++++ .../increment/inc_func_ref.params.yaml | 69 +++++++++ .../increment/inc_func_val.ets | 36 +++++ .../increment/inc_func_val.params.yaml | 69 +++++++++ .../subtraction/sub_arr_ref.ets | 31 ++++ .../subtraction/sub_arr_ref.params.yaml | 48 +++++++ .../subtraction/sub_arr_val.ets | 31 ++++ .../subtraction/sub_arr_val.params.yaml | 48 +++++++ .../subtraction/sub_func_ref.ets | 32 +++++ .../subtraction/sub_func_ref.params.yaml | 48 +++++++ .../subtraction/sub_func_val.ets | 32 +++++ .../subtraction/sub_func_val.params.yaml | 48 +++++++ .../unary/unary_ref.ets | 35 +++++ .../unary/unary_ref.params.yaml | 41 ++++++ .../unary/unary_val.ets | 35 +++++ .../unary/unary_val.params.yaml | 41 ++++++ .../runner/plugins/ets/ets-cts-ignored.txt | 136 +++++++++++++++--- 57 files changed, 2299 insertions(+), 19 deletions(-) create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc2.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc2.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_ref.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_ref.params.yaml create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_val.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_val.params.yaml diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref.ets new file mode 100644 index 000000000..79dcc3577 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref.ets @@ -0,0 +1,31 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +const a: Char[] = new Char[1] + +function main() { + const v1 = new Char({{v.v1}}) + const v2 = new Char({{v.v2}}) + + a[0] = {{v.exp}} // unboxing/boxing is expected here + assert a[0] == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref.params.yaml new file mode 100644 index 000000000..d0417a740 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref.params.yaml @@ -0,0 +1,48 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + exp: 'v1 + v2' + r: c'A' + + - v1: c'\u0020' + v2: c'\u0001' + exp: "v1 + v2 + c' '" + r: c'A' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + exp: "v1 + v2" + r: c'\uFFFE' + + - v1: c'\uFFFF' + v2: c'\u0001' + exp: "v1 + v2" + r: c'\u0000' + + - v1: c'\uFFFF' + v2: c'\u000F' + exp: "v1 + c'\\u000F'" + r: c'\u000E' + + - v1: c'\u1010' + v2: c'\u0101' + exp: "v1 + c'\\u1010' + v2 + c'\\u0101'" + r: c'\u2222' + + - v1: c'∫' + v2: c'\x01' + exp: "v1 + v2" + r: c'∬' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val.ets new file mode 100644 index 000000000..889f670f9 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val.ets @@ -0,0 +1,31 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +const a: char[] = new char[1] + +function main() { + const v1 = {{v.v1}} + const v2 = {{v.v2}} + + a[0] = {{v.exp}} + assert a[0] == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val.params.yaml new file mode 100644 index 000000000..d0417a740 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val.params.yaml @@ -0,0 +1,48 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + exp: 'v1 + v2' + r: c'A' + + - v1: c'\u0020' + v2: c'\u0001' + exp: "v1 + v2 + c' '" + r: c'A' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + exp: "v1 + v2" + r: c'\uFFFE' + + - v1: c'\uFFFF' + v2: c'\u0001' + exp: "v1 + v2" + r: c'\u0000' + + - v1: c'\uFFFF' + v2: c'\u000F' + exp: "v1 + c'\\u000F'" + r: c'\u000E' + + - v1: c'\u1010' + v2: c'\u0101' + exp: "v1 + c'\\u1010' + v2 + c'\\u0101'" + r: c'\u2222' + + - v1: c'∫' + v2: c'\x01' + exp: "v1 + v2" + r: c'∬' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref.ets new file mode 100644 index 000000000..96b9fe2a3 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref.ets @@ -0,0 +1,32 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function add(p: Char, q: Char): Char { + return p + q // unboxing/boxing is expected here +} + +function main() { + const v1 = new Char({{v.v1}}) + const v2 = new Char({{v.v2}}) + + assert ({{v.exp}}) == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref.params.yaml new file mode 100644 index 000000000..86a19326c --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref.params.yaml @@ -0,0 +1,48 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + exp: 'add(v1, v2)' + r: c'A' + + - v1: c'\u0020' + v2: c'\u0001' + exp: "add(v1, v2) + c' '" + r: c'A' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + exp: "add(v1, v2)" + r: c'\uFFFE' + + - v1: c'\uFFFF' + v2: c'\u0001' + exp: "add(v1, v2)" + r: c'\u0000' + + - v1: c'\uFFFF' + v2: c'\u000F' + exp: "add(v1, c'\\u000F')" + r: c'\u000E' + + - v1: c'\u1010' + v2: c'\u0101' + exp: "add(v1 + c'\\u1010', v2 + c'\\u0101')" + r: c'\u2222' + + - v1: c'∫' + v2: c'\x01' + exp: "add(v1, v2)" + r: c'∬' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_val.ets new file mode 100644 index 000000000..3e2ef0d27 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_val.ets @@ -0,0 +1,32 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function add(p: char, q: char): char { + return p + q +} + +function main() { + const v1 = {{v.v1}} + const v2 = {{v.v2}} + + assert ({{v.exp}}) == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_val.params.yaml new file mode 100644 index 000000000..86a19326c --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/addition/add_func_val.params.yaml @@ -0,0 +1,48 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + exp: 'add(v1, v2)' + r: c'A' + + - v1: c'\u0020' + v2: c'\u0001' + exp: "add(v1, v2) + c' '" + r: c'A' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + exp: "add(v1, v2)" + r: c'\uFFFE' + + - v1: c'\uFFFF' + v2: c'\u0001' + exp: "add(v1, v2)" + r: c'\u0000' + + - v1: c'\uFFFF' + v2: c'\u000F' + exp: "add(v1, c'\\u000F')" + r: c'\u000E' + + - v1: c'\u1010' + v2: c'\u0101' + exp: "add(v1 + c'\\u1010', v2 + c'\\u0101')" + r: c'\u2222' + + - v1: c'∫' + v2: c'\x01' + exp: "add(v1, v2)" + r: c'∬' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.ets new file mode 100644 index 000000000..4ca188229 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.ets @@ -0,0 +1,25 @@ +/*--- +Copyright (c) 2021-2023 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: check addition of two bytes +tags: [compile-only, negative] +---*/ + +function main() { + const v = {{c.exp}} +} +{% endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.params.yaml new file mode 100644 index 000000000..24bd9072f --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.params.yaml @@ -0,0 +1,27 @@ +# Copyright (c) 2021-2023 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: + - exp: c'0' * c'2' + - exp: c'1' / c'1' + - exp: c'2' % c'2' + - exp: c'2' >> c'2' + - exp: c'2' >>> c'2' + - exp: c'2' << c'2' + - exp: c'2' & c'2' + - exp: c'2' && c'2' + - exp: c'2' | c'2' + - exp: c'2' || c'2' + - exp: c'2' ^ c'2' + - exp: "!c'2' && !c'2'" diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_ref.ets new file mode 100644 index 000000000..c744a32bd --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_ref.ets @@ -0,0 +1,30 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Comparison operators that produce a value of type boolean. +---*/ + +function main() { + const v1: Char = new Char({{v.v1}}) + const v2: Char = new Char({{v.v2}}) + + {%- for c in v.cases %} + assert (v1 {{c.op}} v2) == {{c.r}} + {%- endfor %} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_ref.params.yaml new file mode 100644 index 000000000..432850f23 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_ref.params.yaml @@ -0,0 +1,53 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0000' + v2: c'\u0000' + cases: + - { op: '==', r: 'true' } + - { op: '!=', r: 'false' } + - { op: '<', r: 'false' } + - { op: '<=', r: 'true' } + - { op: '>', r: 'false' } + - { op: '>=', r: 'true' } + + - v1: c'\uFFFF' + v2: c'\uFFFF' + cases: + - { op: '==', r: 'true' } + - { op: '!=', r: 'false' } + - { op: '<', r: 'false' } + - { op: '<=', r: 'true' } + - { op: '>', r: 'false' } + - { op: '>=', r: 'true' } + + - v1: c'\u000F' + v2: c'\uF000' + cases: + - { op: '==', r: 'false' } + - { op: '!=', r: 'true' } + - { op: '<', r: 'true' } + - { op: '<=', r: 'true' } + - { op: '>', r: 'false' } + - { op: '>=', r: 'false' } + + - v1: c'\u0100' + v2: c'\u00FF' + cases: + - { op: '==', r: 'false' } + - { op: '!=', r: 'true' } + - { op: '<', r: 'false' } + - { op: '<=', r: 'false' } + - { op: '>', r: 'true' } + - { op: '>=', r: 'true' } diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_val.ets new file mode 100644 index 000000000..08b6bcae9 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_val.ets @@ -0,0 +1,30 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Comparison operators that produce a value of type boolean. +---*/ + +function main() { + const v1: char = {{v.v1}} + const v2: char = {{v.v2}} + + {%- for c in v.cases %} + assert (v1 {{c.op}} v2) == {{c.r}} + {%- endfor %} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_val.params.yaml new file mode 100644 index 000000000..432850f23 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/comparison/cmp_val.params.yaml @@ -0,0 +1,53 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0000' + v2: c'\u0000' + cases: + - { op: '==', r: 'true' } + - { op: '!=', r: 'false' } + - { op: '<', r: 'false' } + - { op: '<=', r: 'true' } + - { op: '>', r: 'false' } + - { op: '>=', r: 'true' } + + - v1: c'\uFFFF' + v2: c'\uFFFF' + cases: + - { op: '==', r: 'true' } + - { op: '!=', r: 'false' } + - { op: '<', r: 'false' } + - { op: '<=', r: 'true' } + - { op: '>', r: 'false' } + - { op: '>=', r: 'true' } + + - v1: c'\u000F' + v2: c'\uF000' + cases: + - { op: '==', r: 'false' } + - { op: '!=', r: 'true' } + - { op: '<', r: 'true' } + - { op: '<=', r: 'true' } + - { op: '>', r: 'false' } + - { op: '>=', r: 'false' } + + - v1: c'\u0100' + v2: c'\u00FF' + cases: + - { op: '==', r: 'false' } + - { op: '!=', r: 'true' } + - { op: '<', r: 'false' } + - { op: '<=', r: 'false' } + - { op: '>', r: 'true' } + - { op: '>=', r: 'true' } diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc2.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc2.ets new file mode 100644 index 000000000..c2bfe7821 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc2.ets @@ -0,0 +1,25 @@ +/*--- +Copyright (c) 2021-2023 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. +---*/ +/*--- +desc: >- + The string concatenation operator '+' (see String Concatenation), which (if a string operand and character + operand are available) converts the character operand to a string and then creates a concatenation of + the two strings as a new string. +---*/ +function main() { +{%- for v in vals %} + assert {{v.expr}} == {{v.res}} +{%- endfor %} +} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc2.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc2.params.yaml new file mode 100644 index 000000000..aa7474f3a --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc2.params.yaml @@ -0,0 +1,39 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - expr: "'a' + c'b' + 'c' + c'd'" + res: '"abcd"' + - expr: "'a' + c'b' + c'c' + c'd'" + res: '"abcd"' + - expr: "c'a' + 'b' + 'c' + c'd'" + res: '"abcd"' + - expr: "c'a' + c'b' + c'c' + c'd'" + res: c'Ɗ' + - expr: "c'a' + c'b' + c'c' + 'd'" + res: '"Ħd"' + - expr: "c'a' + c'b' + 'c' + 'd'" + res: '"Ãcd"' + + - expr: "'a' + new Char(c'b') + 'c' + new Char(c'd')" + res: '"abcd"' + - expr: "'a' + new Char(c'b') + new Char(c'c') + new Char(c'd')" + res: '"abcd"' + - expr: "new Char(c'a') + 'b' + 'c' + new Char(c'd')" + res: '"abcd"' + - expr: "new Char(c'a') + new Char(c'b') + new Char(c'c') + new Char(c'd')" + res: c'Ɗ' + - expr: "new Char(c'a') + new Char(c'b') + new Char(c'c') + 'd'" + res: '"Ħd"' + - expr: "new Char(c'a') + new Char(c'b') + 'c' + 'd'" + res: '"Ãcd"' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_ref.ets new file mode 100644 index 000000000..173bea549 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_ref.ets @@ -0,0 +1,38 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + The string concatenation operator '+' (see String Concatenation), which (if a string operand and character + operand are available) converts the character operand to a string and then creates a concatenation of + the two strings as a new string. +---*/ +function main() { + const v1 = new Char({{v.v1}}) + const v2 = new Char({{v.v2}}) + + assert "" + v1 + v2 == {{v.r1}} + assert v1 + "" + v2 == {{v.r1}} + assert v1 + v2 + "" == {{v.r2}} + + assert "" + {{v.v1}} + v2 == {{v.r1}} + assert {{v.v1}} + "" + v2 == {{v.r1}} + assert {{v.v1}} + v2 + "" == {{v.r2}} + + assert "" + {{v.v1}} + {{v.v2}} == {{v.r1}} + assert {{v.v1}} + "" + {{v.v2}} == {{v.r1}} + assert {{v.v1}} + {{v.v2}} + "" == {{v.r2}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_ref.params.yaml new file mode 100644 index 000000000..157a114e3 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_ref.params.yaml @@ -0,0 +1,38 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + r1: '" !"' + r2: '"A"' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + r1: '"\uFFFF\uFFFF"' + r2: '"\uFFFE"' + + - v1: c'\uFFFF' + v2: c'\u0000' + r1: '"\uFFFF\u0000"' + r2: '"\uFFFF"' + + - v1: c'\u2200' + v2: c'\u002C' + r1: '"∀,"' + r2: '"∬"' + + - v1: c'1' + v2: c'2' + r1: '"12"' + r2: '"c"' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_val.ets new file mode 100644 index 000000000..536ea8f31 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_val.ets @@ -0,0 +1,38 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + The string concatenation operator '+' (see String Concatenation), which (if a string operand and character + operand are available) converts the character operand to a string and then creates a concatenation of + the two strings as a new string. +---*/ +function main() { + let v1 = {{v.v1}} + let v2 = {{v.v2}} + + assert "" + v1 + v2 == {{v.r1}} + assert v1 + "" + v2 == {{v.r1}} + assert v1 + v2 + "" == {{v.r2}} + + assert "" + {{v.v1}} + v2 == {{v.r1}} + assert {{v.v1}} + "" + v2 == {{v.r1}} + assert {{v.v1}} + v2 + "" == {{v.r2}} + + assert "" + {{v.v1}} + {{v.v2}} == {{v.r1}} + assert {{v.v1}} + "" + {{v.v2}} == {{v.r1}} + assert {{v.v1}} + {{v.v2}} + "" == {{v.r2}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_val.params.yaml new file mode 100644 index 000000000..157a114e3 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/concat/conc_val.params.yaml @@ -0,0 +1,38 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + r1: '" !"' + r2: '"A"' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + r1: '"\uFFFF\uFFFF"' + r2: '"\uFFFE"' + + - v1: c'\uFFFF' + v2: c'\u0000' + r1: '"\uFFFF\u0000"' + r2: '"\uFFFF"' + + - v1: c'\u2200' + v2: c'\u002C' + r1: '"∀,"' + r2: '"∬"' + + - v1: c'1' + v2: c'2' + r1: '"12"' + r2: '"c"' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val.ets new file mode 100644 index 000000000..61004b7e2 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val.ets @@ -0,0 +1,30 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Conditional operator ‘?:’ (see Conditional Expressions); +---*/ + +class A { + static b: boolean = {{v.b}} + static r: char = {{v.r}} +} + +function main() { + assert A.r - (A.b ? {{v.v1}} : {{v.v2}}) == c'\u0000' +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val.params.yaml new file mode 100644 index 000000000..b0dbf41ae --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val.params.yaml @@ -0,0 +1,34 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + b: 'true' + r: c' ' + + - v1: c'\u0020' + v2: c'\uF041' + b: 'false' + r: c'A' + c'\uF000' + + - v1: c'\uFFFE' + c'\u0023' + v2: c'\u0021' + c'\u0001' + b: 'true' + r: c'!' + + - v1: 65535 as char + v2: 65534 as char + b: 'true' + r: c'\uFFFF' + diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val.ets new file mode 100644 index 000000000..610e3a70a --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val.ets @@ -0,0 +1,32 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Conditional operator ‘?:’ (see Conditional Expressions); +---*/ + +class A { + static b: boolean = {{v.b}} + static v1: char = {{v.v1}} + static v2: char = {{v.v2}} + static r: char = {{v.r}} +} + +function main() { + assert (A.b ? A.v1 : A.v2) == A.r +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val.params.yaml new file mode 100644 index 000000000..b94ed9f6a --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val.params.yaml @@ -0,0 +1,28 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + b: 'true' + r: c' ' + + - v1: c'\u0020' + v2: c'\uF041' + b: 'false' + r: c'A' + c'\uF000' + + - v1: c'\uFFFE' + c'\u0023' + v2: c'\u0021' + c'\u0001' + b: 'true' + r: c'!' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref.ets new file mode 100644 index 000000000..ebcefaf9b --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref.ets @@ -0,0 +1,32 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Conditional operator ‘?:’ (see Conditional Expressions); +---*/ + +function foo(c: boolean, p: Char, q: Char): Char { + return c ? p : q +} + +function main() { + const v1 = new Char({{v.v1}}) + const v2 = new Char({{v.v2}}) + + assert ({{v.exp}}) == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref.params.yaml new file mode 100644 index 000000000..987a25759 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref.params.yaml @@ -0,0 +1,38 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + exp: foo(true, v1, v2) + r: c' ' + + - v1: c'\u0020' + v2: c'\u0021' + exp: foo(false, v1, v2) + v1 + r: c'A' + + - v1: c'\u0020' + v2: c'\u0021' + exp: '" " + foo(false, v1, v2) + v1' + r: "' ! '" + + - v1: c'\u0020' + v2: c'\u0021' + exp: "c' ' + foo(false, v1, v2) + v1" + r: c'a' + + - v1: c'\u0020' + v2: c'\u0021' + exp: "c' ' + foo(false, v2 + v1, v2 - v1)" + r: v2 diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val.ets new file mode 100644 index 000000000..af27bd37b --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val.ets @@ -0,0 +1,32 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Conditional operator ‘?:’ (see Conditional Expressions); +---*/ + +function foo(c: boolean, p: char, q: char): char { + return c ? p : q +} + +function main() { + const v1 = {{v.v1}} + const v2 = {{v.v2}} + + assert ({{v.exp}}) == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val.params.yaml new file mode 100644 index 000000000..9c11aa021 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val.params.yaml @@ -0,0 +1,38 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0021' + exp: foo(true, v1, v2) + r: c' ' + + - v1: c'\u0020' + v2: c'\u0021' + exp: foo(false, v1, v2) + v + r: c'A' + + - v1: c'\u0020' + v2: c'\u0021' + exp: '" " + foo(false, v1, v2) + v1' + r: ' ! ' + + - v1: c'\u0020' + v2: c'\u0021' + exp: "c' ' + foo(false, v1, v2) + v1" + r: c'a' + + - v1: c'\u0020' + v2: c'\u0021' + exp: "c' ' + foo(false, v2 + v1, v2 - v1)" + r: v2 diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_ref.ets new file mode 100644 index 000000000..2bcacfe64 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_ref.ets @@ -0,0 +1,34 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +const a: Char[] = new Char[2] + +function main() { + let v1 = new Char({{v.v1}}) + + a[0] = --v1 + v1-- + a[1] = v1 + + assert a[0] == {{v.r1}} + assert a[1] == {{v.r2}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_ref.params.yaml new file mode 100644 index 000000000..e1cf92dce --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_ref.params.yaml @@ -0,0 +1,33 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0022' + r1: c'!' + r2: c' ' + + - v1: c'\x00' + r1: c'\uFFFF' + r2: c'\uFFFE' + + - v1: c'\u1110' + r1: c'\u110F' + r2: c'\u110E' + + - v1: c'\u0001' + r1: c'\u0000' + r2: c'\uFFFF' + + - v1: c'∭' + r1: c'∬' + r2: c'∫' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_val.ets new file mode 100644 index 000000000..f8eaca85e --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_val.ets @@ -0,0 +1,34 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +const a: char[] = new char[2] + +function main() { + let v1 = {{v.v1}} + + a[0] = --v1 + v1-- + a[1] = v1 + + assert a[0] == {{v.r1}} + assert a[1] == {{v.r2}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_val.params.yaml new file mode 100644 index 000000000..e1cf92dce --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_arr_val.params.yaml @@ -0,0 +1,33 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0022' + r1: c'!' + r2: c' ' + + - v1: c'\x00' + r1: c'\uFFFF' + r2: c'\uFFFE' + + - v1: c'\u1110' + r1: c'\u110F' + r2: c'\u110E' + + - v1: c'\u0001' + r1: c'\u0000' + r2: c'\uFFFF' + + - v1: c'∭' + r1: c'∬' + r2: c'∫' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref.ets new file mode 100644 index 000000000..422f0c7e5 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref.ets @@ -0,0 +1,36 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function decPre(p: Char): Char { + return --p +} + +function decPost(p: Char): Char { + p-- + return p +} + +function main() { + const v1 = new Char({{v.v1}}) + + assert ({{v.exp}}) == {{v.res}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref.params.yaml new file mode 100644 index 000000000..48363f1ce --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref.params.yaml @@ -0,0 +1,69 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0021' + exp: 'decPre(v1)' + res: c' ' + + - v1: c'\u0022' + exp: 'decPost(v1)' + res: c'!' + + - v1: c'"' + exp: "c' ' + decPre(v1)" + res: c'A' + + - v1: c'\u0020' + exp: "c' ' + decPost(v1)" + res: c'?' + + - v1: c'\u0000' + exp: "decPre(v1)" + res: c'\uFFFF' + + - v1: c'\u0000' + exp: "decPost(v1)" + res: c'\uFFFF' + + - v1: c'\u00FF' + exp: "decPre(c'!' + v1 + v1)" + res: c'\u021E' + + - v1: c'\u0001' + exp: "decPost(v1 - c'!' - v1)" + res: c'\uFFDE' + + - v1: c'\u0F0F' + exp: "decPre(v1 - c'1') - decPre(c'\\uACD9')" + res: c'\u6205' + + - v1: c'\u0F0F' + exp: "decPost(v1 + c'1') + decPost(c'\\uACD9')" + res: c'\uBC17' + + - v1: c'\u1110' + exp: "decPre(c'\\u0000') - decPre(v1)" + res: c'\uEEF0' + + - v1: c'\u1000' + exp: "decPost(c'\\u0000') - decPost(v1)" + res: c'\uF000' + + - v1: c'∬' + exp: "decPre(v1)" + res: c'∫' + + - v1: c'∬' + exp: "decPost(v1)" + res: c'∫' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val.ets new file mode 100644 index 000000000..32e4a17ac --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val.ets @@ -0,0 +1,36 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function decPre(p: char): char { + return --p +} + +function decPost(p: char): char { + p-- + return p +} + +function main() { + const v1 = {{v.v1}} + + assert ({{v.exp}}) == {{v.res}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val.params.yaml new file mode 100644 index 000000000..48363f1ce --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val.params.yaml @@ -0,0 +1,69 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0021' + exp: 'decPre(v1)' + res: c' ' + + - v1: c'\u0022' + exp: 'decPost(v1)' + res: c'!' + + - v1: c'"' + exp: "c' ' + decPre(v1)" + res: c'A' + + - v1: c'\u0020' + exp: "c' ' + decPost(v1)" + res: c'?' + + - v1: c'\u0000' + exp: "decPre(v1)" + res: c'\uFFFF' + + - v1: c'\u0000' + exp: "decPost(v1)" + res: c'\uFFFF' + + - v1: c'\u00FF' + exp: "decPre(c'!' + v1 + v1)" + res: c'\u021E' + + - v1: c'\u0001' + exp: "decPost(v1 - c'!' - v1)" + res: c'\uFFDE' + + - v1: c'\u0F0F' + exp: "decPre(v1 - c'1') - decPre(c'\\uACD9')" + res: c'\u6205' + + - v1: c'\u0F0F' + exp: "decPost(v1 + c'1') + decPost(c'\\uACD9')" + res: c'\uBC17' + + - v1: c'\u1110' + exp: "decPre(c'\\u0000') - decPre(v1)" + res: c'\uEEF0' + + - v1: c'\u1000' + exp: "decPost(c'\\u0000') - decPost(v1)" + res: c'\uF000' + + - v1: c'∬' + exp: "decPre(v1)" + res: c'∫' + + - v1: c'∬' + exp: "decPost(v1)" + res: c'∫' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref.ets new file mode 100644 index 000000000..2acd9331d --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref.ets @@ -0,0 +1,34 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +const a: Char[] = new Char[2] + +function main() { + let v1 = new Char({{v.v1}}) + + a[0] = ++v1 + v1++ + a[1] = v1 + + assert a[0] == {{v.r1}} + assert a[1] == {{v.r2}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref.params.yaml new file mode 100644 index 000000000..99c330c86 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref.params.yaml @@ -0,0 +1,37 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + r1: c'!' + r2: c'"' + + - v1: c'\x00' + r1: c'\x01' + r2: c'\x02' + + - v1: c'\uFFFF' + r1: c'\u0000' + r2: c'\u0001' + + - v1: c'\u007F' + r1: c'\u0080' + r2: c'\u0081; + + - v1: c'\u00FF' + r1: c'\u0100' + r2: c'\u0101; + + - v1: c'∫' + r1: c'∬' + r2: c'∭' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val.ets new file mode 100644 index 000000000..0266760cf --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val.ets @@ -0,0 +1,34 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +const a: char[] = new char[2] + +function main() { + let v1 = {{v.v1}} + + a[0] = ++v1 + v1++ + a[1] = v1 + + assert a[0] == {{v.r1}} + assert a[1] == {{v.r2}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val.params.yaml new file mode 100644 index 000000000..99c330c86 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val.params.yaml @@ -0,0 +1,37 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + r1: c'!' + r2: c'"' + + - v1: c'\x00' + r1: c'\x01' + r2: c'\x02' + + - v1: c'\uFFFF' + r1: c'\u0000' + r2: c'\u0001' + + - v1: c'\u007F' + r1: c'\u0080' + r2: c'\u0081; + + - v1: c'\u00FF' + r1: c'\u0100' + r2: c'\u0101; + + - v1: c'∫' + r1: c'∬' + r2: c'∭' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref.ets new file mode 100644 index 000000000..471ba5131 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref.ets @@ -0,0 +1,36 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function incPre(p: Char): Char { + return ++p +} + +function incPost(p: Char): Char { + p++ + return p +} + +function main() { + const v1 = new Char({{v.v1}}) + + assert ({{v.exp}}) == {{v.res}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref.params.yaml new file mode 100644 index 000000000..d72c66667 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref.params.yaml @@ -0,0 +1,69 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + exp: 'incPre(v1)' + res: c'!' + + - v1: c'\u0020' + exp: 'incPost(v1)' + res: c'!' + + - v1: c'\u0020' + exp: "c' ' + incPre(v1)" + res: c'A' + + - v1: c'\u0020' + exp: "c' ' + incPost(v1)" + res: c'A' + + - v1: c'\uFFFF' + exp: "incPre(v1)" + res: c'\x00' + + - v1: c'\uFFFF' + exp: "incPost(v1)" + res: c'\x00' + + - v1: c'\uFFFF' + exp: "incPre(c'!' + v1 + v1)" + res: c'\u0020' + + - v1: c'\uFFFF' + exp: "incPost(c'!' + v1 + v1)" + res: c'\u0020' + + - v1: c'\u0F0F' + exp: "incPre(v1 + c'1') + incPre(c'\\uACD9')" + res: c'\uBC1B' + + - v1: c'\u0F0F' + exp: "incPost(v1 + c'1') + incPost(c'\\uACD9')" + res: c'\uBC1B' + + - v1: c'\u007F' + exp: "incPre(c'\\u0000') + incPre(v1)" + res: c'\u0081' + + - v1: c'\u007F' + exp: "incPost(c'\\u0000') + incPost(v1)" + res: c'\u0081' + + - v1: c'∫' + exp: "incPre(v1)" + res: c'∬' + + - v1: c'∫' + exp: "incPost(v1)" + res: c'∬' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val.ets new file mode 100644 index 000000000..9c26217d2 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val.ets @@ -0,0 +1,36 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function incPre(p: char): char { + return ++p +} + +function incPost(p: char): char { + p++ + return p +} + +function main() { + const v1 = {{v.v1}} + + assert ({{v.exp}}) == {{v.res}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val.params.yaml new file mode 100644 index 000000000..d72c66667 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val.params.yaml @@ -0,0 +1,69 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + exp: 'incPre(v1)' + res: c'!' + + - v1: c'\u0020' + exp: 'incPost(v1)' + res: c'!' + + - v1: c'\u0020' + exp: "c' ' + incPre(v1)" + res: c'A' + + - v1: c'\u0020' + exp: "c' ' + incPost(v1)" + res: c'A' + + - v1: c'\uFFFF' + exp: "incPre(v1)" + res: c'\x00' + + - v1: c'\uFFFF' + exp: "incPost(v1)" + res: c'\x00' + + - v1: c'\uFFFF' + exp: "incPre(c'!' + v1 + v1)" + res: c'\u0020' + + - v1: c'\uFFFF' + exp: "incPost(c'!' + v1 + v1)" + res: c'\u0020' + + - v1: c'\u0F0F' + exp: "incPre(v1 + c'1') + incPre(c'\\uACD9')" + res: c'\uBC1B' + + - v1: c'\u0F0F' + exp: "incPost(v1 + c'1') + incPost(c'\\uACD9')" + res: c'\uBC1B' + + - v1: c'\u007F' + exp: "incPre(c'\\u0000') + incPre(v1)" + res: c'\u0081' + + - v1: c'\u007F' + exp: "incPost(c'\\u0000') + incPost(v1)" + res: c'\u0081' + + - v1: c'∫' + exp: "incPre(v1)" + res: c'∬' + + - v1: c'∫' + exp: "incPost(v1)" + res: c'∬' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref.ets new file mode 100644 index 000000000..f3b8a0845 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref.ets @@ -0,0 +1,31 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +const a: Char[] = new Char[1] + +function main() { + const v1 = new Char({{v.v1}}) + const v2 = new Char({{v.v2}}) + + a[0] = {{v.exp}} + assert a[0] == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref.params.yaml new file mode 100644 index 000000000..6521acad4 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref.params.yaml @@ -0,0 +1,48 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0041' + exp: 'v2 - v1' + r: c'!' + + - v1: c'\u0041' + v2: c'\u0001' + exp: "v1 - v2 - c' '" + r: c' ' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + exp: 'v1 - v2' + r: c'\u0000' + + - v1: c'\uFFFF' + v2: c'\u0000' + exp: 'v2 - v1' + r: c'\u0001' + + - v1: c'\uFFFF' + v2: c'\u000F' + exp: "c'\\u000F' - v1" + r: c'\u0010' + + - v1: c'\u1010' + v2: c'\u0101' + exp: "v1 - c'\\u0101' - v2 - c'\\u1010'" + r: c'\uFDFE' + + - v1: c'∬' + v2: c'\x01' + exp: 'v1 - v2' + r: c'∫' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val.ets new file mode 100644 index 000000000..889f670f9 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val.ets @@ -0,0 +1,31 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +const a: char[] = new char[1] + +function main() { + const v1 = {{v.v1}} + const v2 = {{v.v2}} + + a[0] = {{v.exp}} + assert a[0] == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val.params.yaml new file mode 100644 index 000000000..6521acad4 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val.params.yaml @@ -0,0 +1,48 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0041' + exp: 'v2 - v1' + r: c'!' + + - v1: c'\u0041' + v2: c'\u0001' + exp: "v1 - v2 - c' '" + r: c' ' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + exp: 'v1 - v2' + r: c'\u0000' + + - v1: c'\uFFFF' + v2: c'\u0000' + exp: 'v2 - v1' + r: c'\u0001' + + - v1: c'\uFFFF' + v2: c'\u000F' + exp: "c'\\u000F' - v1" + r: c'\u0010' + + - v1: c'\u1010' + v2: c'\u0101' + exp: "v1 - c'\\u0101' - v2 - c'\\u1010'" + r: c'\uFDFE' + + - v1: c'∬' + v2: c'\x01' + exp: 'v1 - v2' + r: c'∫' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref.ets new file mode 100644 index 000000000..c12a5ad80 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref.ets @@ -0,0 +1,32 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function sub(p: Char, q: Char): Char { + return p - q +} + +function main() { + const v1 = new Char({{v.v1}}) + const v2 = new Char({{v.v2}}) + + assert ({{v.exp}}) == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref.params.yaml new file mode 100644 index 000000000..38c8a3a2b --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref.params.yaml @@ -0,0 +1,48 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0041' + exp: 'sub(v2, v1)' + r: c'!' + + - v1: c'\u0041' + v2: c'\u0001' + exp: "sub(v1, v2) - c' '" + r: c' ' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + exp: 'sub(v1, v2)' + r: c'\u0000' + + - v1: c'\uFFFF' + v2: c'\u0000' + exp: 'sub(v2, v1)' + r: c'\u0001' + + - v1: c'\uFFFF' + v2: c'\u000F' + exp: "sub(c'\\u000F', v1)" + r: c'\u0010' + + - v1: c'\u1010' + v2: c'\u0101' + exp: "sub(v1 - c'\\u0101', v2 - c'\\u1010')" + r: c'\u1E1E' + + - v1: c'∬' + v2: c'\x01' + exp: 'sub(v1, v2)' + r: c'∫' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val.ets new file mode 100644 index 000000000..ad928ef5b --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val.ets @@ -0,0 +1,32 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function sub(p: char, q: char): char { + return p - q +} + +function main() { + const v1 = {{v.v1}} + const v2 = {{v.v2}} + + assert ({{v.exp}}) == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val.params.yaml new file mode 100644 index 000000000..38c8a3a2b --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val.params.yaml @@ -0,0 +1,48 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + v2: c'\u0041' + exp: 'sub(v2, v1)' + r: c'!' + + - v1: c'\u0041' + v2: c'\u0001' + exp: "sub(v1, v2) - c' '" + r: c' ' + + - v1: c'\uFFFF' + v2: c'\uFFFF' + exp: 'sub(v1, v2)' + r: c'\u0000' + + - v1: c'\uFFFF' + v2: c'\u0000' + exp: 'sub(v2, v1)' + r: c'\u0001' + + - v1: c'\uFFFF' + v2: c'\u000F' + exp: "sub(c'\\u000F', v1)" + r: c'\u0010' + + - v1: c'\u1010' + v2: c'\u0101' + exp: "sub(v1 - c'\\u0101', v2 - c'\\u1010')" + r: c'\u1E1E' + + - v1: c'∬' + v2: c'\x01' + exp: 'sub(v1, v2)' + r: c'∫' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_ref.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_ref.ets new file mode 100644 index 000000000..5fc15f990 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_ref.ets @@ -0,0 +1,35 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function minus(p: Char): Char { + return -p +} + +function plus(p: Char): Char { + return +p +} + +function main() { + const v1 = new Char({{v.v1}}) + + assert ({{v.exp}}) == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_ref.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_ref.params.yaml new file mode 100644 index 000000000..c4baf0ac2 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_ref.params.yaml @@ -0,0 +1,41 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + exp: 'minus(plus(v1)) - plus(minus(v1))' + r: c'\u0000' + + - v1: c'∬' + exp: 'plus(v1)' + r: c'∬' + + - v1: c'∬' + exp: 'minus(v1)' + r: c'\uDDD4' + + - v1: c'\uFFFF' + exp: 'minus(v1)' + r: c'\u0001' + + - v1: c'\uFFFF' + exp: 'plus(v1)' + r: c'\uFFFF' + + - v1: c'\u0000' + exp: 'minus(v1)' + r: c'\u0000' + + - v1: c'\u0000' + exp: 'plus(v1)' + r: c'\u0000' diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_val.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_val.ets new file mode 100644 index 000000000..d4f9b8ea3 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_val.ets @@ -0,0 +1,35 @@ +/*--- +Copyright (c) 2021-2023 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 v in vals %} +/*--- +desc: >- + ArkTS provides a number of operators to act on character values: + Character operators that produce a value of type char. +---*/ + +function minus(p: char): char { + return -p +} + +function plus(p: char): char { + return +p +} + +function main() { + const v1 = {{v.v1}} + + assert ({{v.exp}}) == {{v.r}} +} +{%- endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_val.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_val.params.yaml new file mode 100644 index 000000000..c4baf0ac2 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/unary/unary_val.params.yaml @@ -0,0 +1,41 @@ +# Copyright (c) 2021-2023 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. +--- +vals: + - v1: c'\u0020' + exp: 'minus(plus(v1)) - plus(minus(v1))' + r: c'\u0000' + + - v1: c'∬' + exp: 'plus(v1)' + r: c'∬' + + - v1: c'∬' + exp: 'minus(v1)' + r: c'\uDDD4' + + - v1: c'\uFFFF' + exp: 'minus(v1)' + r: c'\u0001' + + - v1: c'\uFFFF' + exp: 'plus(v1)' + r: c'\uFFFF' + + - v1: c'\u0000' + exp: 'minus(v1)' + r: c'\u0000' + + - v1: c'\u0000' + exp: 'plus(v1)' + r: c'\u0000' diff --git a/tests/tests-u-runner/runner/plugins/ets/ets-cts-ignored.txt b/tests/tests-u-runner/runner/plugins/ets/ets-cts-ignored.txt index 63e4c0c49..f31d42afd 100644 --- a/tests/tests-u-runner/runner/plugins/ets/ets-cts-ignored.txt +++ b/tests/tests-u-runner/runner/plugins/ets/ets-cts-ignored.txt @@ -451,14 +451,6 @@ 07.expressions/01.evaluation_of_expressions/02.normal_and_abrupt_completion_of_expression_evaluation/ase1.ets # end of verifier problems # runtime fails: panda#11542 -03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_byte_3.ets -03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_short_3.ets -03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_byte_4.ets -03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_short_4.ets -03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_byte_3.ets -03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_short_3.ets -03.types/07.value_types/01.integer_types_and_operations/prefix_increment/prefix_increment_byte_4.ets -03.types/07.value_types/01.integer_types_and_operations/prefix_increment/prefix_increment_short_4.ets 03.types/07.value_types/01.integer_types_and_operations/right_shift/right_shift_long_10.ets 03.types/07.value_types/01.integer_types_and_operations/unsigned_right_shift/unsigned_right_shift_byte_7.ets 03.types/07.value_types/01.integer_types_and_operations/unsigned_right_shift/unsigned_right_shift_short_7.ets @@ -986,7 +978,6 @@ 03.types/07.value_types/01.integer_types_and_operations/not_equal/not_equal_ushort_7.ets 03.types/07.value_types/01.integer_types_and_operations/not_equal/not_equal_ushort_8.ets 03.types/07.value_types/01.integer_types_and_operations/not_equal/not_equal_ushort_9.ets -03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_char_2.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_ubyte_0.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_ubyte_1.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_ubyte_2.ets @@ -1008,7 +999,6 @@ 03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_ushort_2.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_ushort_3.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_decrement/postfix_decrement_ushort_4.ets -03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_char_3.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_ubyte_0.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_ubyte_1.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_ubyte_2.ets @@ -1029,7 +1019,6 @@ 03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_ushort_2.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_ushort_3.ets 03.types/07.value_types/01.integer_types_and_operations/postfix_increment/postfix_increment_ushort_4.ets -03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_char_2.ets 03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_ubyte_0.ets 03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_ubyte_1.ets 03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_ubyte_2.ets @@ -1050,7 +1039,6 @@ 03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_ushort_2.ets 03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_ushort_3.ets 03.types/07.value_types/01.integer_types_and_operations/prefix_decrement/prefix_decrement_ushort_4.ets -03.types/07.value_types/01.integer_types_and_operations/prefix_increment/prefix_increment_char_3.ets 03.types/07.value_types/01.integer_types_and_operations/prefix_increment/prefix_increment_ubyte_0.ets 03.types/07.value_types/01.integer_types_and_operations/prefix_increment/prefix_increment_ubyte_1.ets 03.types/07.value_types/01.integer_types_and_operations/prefix_increment/prefix_increment_ubyte_2.ets @@ -1921,6 +1909,123 @@ 05.generics/05.parameterized_declarations/type_arguments_of_parameterized_declarations/method_args1_13.ets # end of verifier fails +# es2panda fails: panda#14140 +03.types/07.value_types/05.character_types_and_operations/ch_n_0.ets +03.types/07.value_types/05.character_types_and_operations/ch_n_1.ets +03.types/07.value_types/05.character_types_and_operations/ch_n_10.ets +03.types/07.value_types/05.character_types_and_operations/ch_n_2.ets +03.types/07.value_types/05.character_types_and_operations/ch_n_3.ets +03.types/07.value_types/05.character_types_and_operations/ch_n_4.ets +03.types/07.value_types/05.character_types_and_operations/ch_n_5.ets +03.types/07.value_types/05.character_types_and_operations/ch_n_6.ets +03.types/07.value_types/05.character_types_and_operations/ch_n_8.ets +# end of es2panda fails + +# es2panda fails: panda#14110 +03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref_6.ets +03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref_7.ets +03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref_8.ets +03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_ref_9.ets +03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val_6.ets +03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val_7.ets +03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val_8.ets +03.types/07.value_types/05.character_types_and_operations/decrement/dec_func_val_9.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref_3.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_ref_4.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val_3.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_arr_val_4.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref_6.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref_7.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref_8.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_func_ref_9.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val_6.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val_7.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val_8.ets +03.types/07.value_types/05.character_types_and_operations/increment/inc_func_val_9.ets +# end of es2panda fails + +# es2panda fails: panda#14105 +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref_0.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref_1.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref_2.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref_3.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref_4.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref_5.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_ref_6.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val_2.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val_3.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_arr_val_4.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref_0.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref_1.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref_2.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref_3.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref_4.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref_5.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_ref_6.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_val_0.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_val_1.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_val_2.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_val_3.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_val_4.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_val_5.ets +03.types/07.value_types/05.character_types_and_operations/addition/add_func_val_6.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref_0.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref_1.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref_2.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref_3.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref_4.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref_5.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_ref_6.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val_3.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val_4.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_arr_val_5.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref_0.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref_1.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref_2.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref_3.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref_4.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref_5.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_ref_6.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val_0.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val_1.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val_2.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val_3.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val_4.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val_5.ets +03.types/07.value_types/05.character_types_and_operations/subtraction/sub_func_val_6.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_ref_0.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_ref_1.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_ref_2.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_ref_3.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_ref_4.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_val_0.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_val_1.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_val_2.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_val_3.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc_val_4.ets +03.types/07.value_types/05.character_types_and_operations/conditional/cond_exp_val_2.ets +03.types/07.value_types/05.character_types_and_operations/conditional/cond_fld_val_2.ets +03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_ref_4.ets +03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val_1.ets +03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val_2.ets +03.types/07.value_types/05.character_types_and_operations/conditional/cond_func_val_4.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_ref_0.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_ref_1.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_ref_2.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_ref_3.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_ref_4.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_ref_5.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_ref_6.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_val_0.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_val_1.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_val_2.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_val_3.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_val_4.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_val_5.ets +03.types/07.value_types/05.character_types_and_operations/unary/unary_val_6.ets +03.types/07.value_types/05.character_types_and_operations/concat/conc2.ets +# end of es2panda fails + # es2panda fails: panda#13203 09.classes/01.class_declaration/06.implementing_interface_properties/getter_setter_implementation.ets 10.interfaces/05.interface_properties/getter_setter_form.ets @@ -1928,10 +2033,3 @@ 10.interfaces/05.interface_properties/readonly_simple_form_0.ets 10.interfaces/05.interface_properties/simple_form.ets # end of es2panda fails - -# es2panda fail: panda#13730 -04.names_declarations_and_scopes/08.function_declarations/03.optional_parameters/opt_param_n_0.ets -04.names_declarations_and_scopes/08.function_declarations/03.optional_parameters/opt_param_n_2.ets -04.names_declarations_and_scopes/08.function_declarations/03.optional_parameters/opt_param_n_10.ets -# end of es2panda fails - -- Gitee From 2f84877a96311fb1a8b64f8c17f5761764d19bcb Mon Sep 17 00:00:00 2001 From: Dmitry Baranov Date: Wed, 11 Oct 2023 15:59:05 +0300 Subject: [PATCH 2/4] [ArkTS][Docs][Cookbook] Updated cookbook Signed-off-by: Dmitry Baranov --- plugins/ets/doc/cookbook/recipes.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/ets/doc/cookbook/recipes.rst b/plugins/ets/doc/cookbook/recipes.rst index 9929c9160..40e0971d1 100644 --- a/plugins/ets/doc/cookbook/recipes.rst +++ b/plugins/ets/doc/cookbook/recipes.rst @@ -3734,8 +3734,8 @@ objects with dynamically changed layout are not supported. .. _R138: -|CB_R| Some of utility types are not supported ----------------------------------------------- +|CB_R| Some utility types are not supported +------------------------------------------- |CB_RULE| ``arkts-no-utility-types`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3745,12 +3745,12 @@ objects with dynamically changed layout are not supported. |CB_ERROR| -Currently |LANG| does not support utility types -from |TS| extensions to the standard library, except following: -``Partial``, ``Required``, ``Readonly``, ``Record``. +Currently |LANG| does not support utility types from |TS| extensions to the +standard library, except ``Partial``, ``Required``, ``Readonly``, and +``Record``. -For the type *Record*, the type of an indexing expression *rec[index]* is -of the type *V | undefined*. +For type *Record*, an indexing expression *rec[index]* is of type +*V | undefined*. |CB_BAD| ~~~~~~~~ -- Gitee From 57c658fe756f82950cfcc2e12b634320ed023bd3 Mon Sep 17 00:00:00 2001 From: Nedoria Aleksei Date: Wed, 11 Oct 2023 12:49:34 +0300 Subject: [PATCH 3/4] [ArkTS][Docs][Spec] Updated spec Signed-off-by: Nedoria Aleksei --- plugins/ets/doc/spec/13_modules.rst | 51 +-- plugins/ets/doc/spec/14_ambients.rst | 6 +- plugins/ets/doc/spec/15_semantics.rst | 2 +- plugins/ets/doc/spec/16_gui.rst | 212 ++++++++++-- plugins/ets/doc/spec/17_experimental.rst | 59 ++-- plugins/ets/doc/spec/1_intro.rst | 212 ++++++------ plugins/ets/doc/spec/2_lexical.rst | 155 +++++---- plugins/ets/doc/spec/3_types.rst | 424 +++++++++++------------ plugins/ets/doc/spec/4_names.rst | 251 +++++++------- plugins/ets/doc/spec/5_generics.rst | 176 ++-------- plugins/ets/doc/spec/6_conversions.rst | 150 +++----- plugins/ets/doc/spec/7_expressions.rst | 128 ++++--- plugins/ets/doc/spec/9_classes.rst | 2 +- 13 files changed, 913 insertions(+), 915 deletions(-) diff --git a/plugins/ets/doc/spec/13_modules.rst b/plugins/ets/doc/spec/13_modules.rst index 93b15a3e8..4b768ecfa 100644 --- a/plugins/ets/doc/spec/13_modules.rst +++ b/plugins/ets/doc/spec/13_modules.rst @@ -574,55 +574,24 @@ using the *export type* form. The difference between *import* and *import type* is that the the first form imports all top-level declarations which were exported while the second one imports only exported types. - -.. - The difference between *import type* and all - other forms of import is that the names of types being imported cannot be used - witin new expressions; the initialization code of a module or a package a type - is imported from is not executed. There are four cases as presented in the - table below: - -.. - +--------+-----------+------------------+ - | | Export | Export Type | - +========+===========+==================+ - | import | no limits | no new, | - | | | no module init | - +--------+-----------+------------------+ - | import | no new, | no new, | - | type | no module | no module init | - | | init | | - +--------+-----------+------------------+ - -.. - If the keyword *type* is used in some import/export directives, then it - immediately changes the manner the *type* can be used. The *type* can only - be used as a parameter type, or as a type of some variable initialized by - a function or a method. - .. code-block:: typescript :linenos: // File module.ets console.log ("Module initialization code") - // Takes care of top-level variables initizlization - export class StandardExportedClass // exported class type + export class Class1 {/*body*/} - class ClassForExport {} - export type {ClassForExport} // class exported as type only + class Class2 {} + export type {Class2} // MainProgram.ets - import type {StandardExportedClass as IT1, ClassForExport as IT2} - from "./module.ets" - import {StandardExportedClass as GIT1, ClassForExport as GIT2} - from "./module.ets" + import {Class1} from "./module.ets" + import type {Class2} from "./module.ets" - let c1 = new IT1 // compile-time error: cannot create objects of type IT1 - let c2 = new IT2 // compile-time error: cannot create objects of type IT2 - let c3 = new GIT1 // OK, `Module initialization code` be printed - let c4 = new GIT2 // compile-time error: cannot create objects of type GIT2 + let c1 = new Class1() // OK + let c2 = new Class2() // OK, the same | @@ -973,11 +942,11 @@ Example below shows how this can be used class A {} - export type {A} // export as type aleady declared class type + export type {A} // export already declared class type - export type MyA = A // name MyA is declared and exported as type + export type MyA = A // name MyA is declared and exported - export type {MyA} // compile-time error as MyA was aleardy exported + export type {MyA} // compile-time error as MyA was already exported | diff --git a/plugins/ets/doc/spec/14_ambients.rst b/plugins/ets/doc/spec/14_ambients.rst index b420ec2de..e7607b419 100644 --- a/plugins/ets/doc/spec/14_ambients.rst +++ b/plugins/ets/doc/spec/14_ambients.rst @@ -259,6 +259,10 @@ Ambient Namespace Declarations ; ambentNamespaceElement: + ambentNamespaceDeclaration | selectiveExportDirective + ; + + ambentNamespaceDeclaration: 'export'? ( ambientVariableDeclaration | ambientFunctionDeclaration @@ -266,7 +270,7 @@ Ambient Namespace Declarations | ambientInterfaceDeclaration | ambientNamespaceDeclaration | enumDeclaration - | typeAlias + | typeAlias ) ; diff --git a/plugins/ets/doc/spec/15_semantics.rst b/plugins/ets/doc/spec/15_semantics.rst index ed89d7e04..02939e59f 100644 --- a/plugins/ets/doc/spec/15_semantics.rst +++ b/plugins/ets/doc/spec/15_semantics.rst @@ -299,7 +299,7 @@ are any valid expressions): +---------+---------+--------+---------+ The example below illustrates the ways this approach works in practice. A -*non-zero* number is truthy, and the loop runs until it becomes *zero*, i.e., +*nonzero* number is truthy, and the loop runs until it becomes *zero*, i.e., falsy. .. code-block:: typescript diff --git a/plugins/ets/doc/spec/16_gui.rst b/plugins/ets/doc/spec/16_gui.rst index 5c047ea56..fb0fc5eb5 100644 --- a/plugins/ets/doc/spec/16_gui.rst +++ b/plugins/ets/doc/spec/16_gui.rst @@ -83,12 +83,12 @@ GUI Structs .. meta: frontend_status: Partly -*GUI structs* are used to define program components. From the language +*GUI structs* are used to define UI components. From the language perspective, a GUI struct is a restricted form of a non-primitive type that is designed to define GUI expressively and efficiently. -Each GUI struct is required to implement its *builder*, which is a method -responsible for visual rendering of components. +Each GUI struct is required to implement its *builder* (i.e., a method +responsible for the visual rendering of components). .. index:: GUI struct @@ -232,7 +232,7 @@ the following is not allowed: - Calling a predefined builder *ForEach* for iterative rendering. - Calling a function that does not mutate the program state (note that all - logging functions are therefore prohibited as they mutate the state). + logging functions are thus prohibited, as they mutate the state). - Using conditional *if ... else* syntax. @@ -264,7 +264,8 @@ Annotations List @Builder Annotation =================== -*Function-level annotation for defining a custom builder* is applicable to: +*Function-level annotation for defining a custom builder* is applicable to +the following: - Methods of GUI structs to define custom builder functions inside a GUI struct. @@ -338,7 +339,7 @@ between a child component *at an arbitrary nesting level*, and a parent component. An *@Consume*-annotated field in a child component shares the same value with -a field in the parent component; the parent component’s source field must be +a field in the parent component. The parent component’s source field must be annotated with *@Provide*. The annotation *@Consume* is applicable only to member fields of GUI structs. @@ -366,12 +367,12 @@ The annotation *@Consume* is applicable only to member fields of GUI structs. @Entry Annotation ================= -*Struct-level annotation to indicate a top-most component on the page* is +*Struct-level annotation to indicate the topmost component on the page* is applicable only to GUI structs. .. index:: struct-level annotation - top-most component + topmost component GUI struct .. code-block:: abnf @@ -392,7 +393,7 @@ applicable only to GUI structs. between a child component and a parent component. An *@Link*-annotated field in a child component shares the same value with a -field in the parent component; the parent component’s source field must be +field in the parent component. The parent component’s source field must be annotated with *@State*, *@StorageLink*, or *@Link*. The annotation *@Link* is applicable only to member fields of GUI structs. @@ -502,7 +503,7 @@ The annotation *@ObjectLink* is applicable only to member fields of GUI structs. ==================== *@Observed* is a class-level annotation that establishes two-way synchronization -between instances of the *@Observed*-annotated class, and *@ObjectLink*-annotated +between instances of an *@Observed*-annotated class, and *@ObjectLink*-annotated member fields of GUI structs. The annotation *@Observed* is applicable only to non-GUI classes. @@ -527,17 +528,17 @@ The annotation *@Observed* is applicable only to non-GUI classes. @Prop Annotation ================ -The annotation *@Prop* has the same semantics as *@State* and only differs in +The annotation *@Prop* has the same semantics as *@State*, and only differs in how the variable must be initialized and updated: - An *@Prop*-annotated field must be initialized with a primitive or - a reference type value provided by its parent component; it must not be + a reference type value provided by its parent component. It must not be initialized locally. - An *@Prop*-annotated field can be modified locally, but the change does not propagate back to its parent component. Whenever that data source changes, the *@Prop*-annotated field is updated, and any - locally-made changes are overwritten; hence, the sync of the value is + locally-made changes are overwritten. Hence, the sync of the value is uni-directional from the parent to the owning component. This annotation *@Prop* is applicable only to member fields of GUI structs. @@ -687,27 +688,27 @@ structs. be executed when the annotated field’s value changes. The annotation *@StorageProp* is applicable only to member fields of GUI -structs also annotated with: +structs with the following annotations: -- *@Consume* +- *@Consume*, -- *@Link* +- *@Link*, -- *@LocalStorageLink* +- *@LocalStorageLink*, -- *@LocalStorageProp* +- *@LocalStorageProp*, -- *@ObjectLink* +- *@ObjectLink*, -- *@Prop* +- *@Prop*, -- *@Provide* +- *@Provide*, -- *@State* +- *@State*, -- *@StorageLink* +- *@StorageLink*, and -- *@StorageProp* +- *@StorageProp*. .. index:: field-level annotation @@ -725,10 +726,165 @@ structs also annotated with: | -.. _Example: +.. _Callable Types: -Example -******* +Callable Types +************** + +.. meta: + frontend_status: Done + +A type is *callable* if the name of the type can be used in a call expression. +A call expression that uses a type's name is called a *type call expression*. +Only class and struct types can be callable. To make a type callable, a static +method with the name '*invoke*' or '*instantiate*' must be defined or inherited. + +.. code-block:: typescript + :linenos: + + class C { + static invoke() { console.log("invoked") } + } + C() // prints: invoked + C.invoke() // also prints: invoked + +In the above example, '*C()*' is a *type call expression*. It is the short +form of the normal method call '*C.invoke()*'. Using an explicit call is always +valid for the methods '*invoke*' and '*instantiate*'. + +**Note**: Only a constructor---not the methods '*invoke*' or +'*instantiate*'---is called in a *new expression*: + +.. code-block:: typescript + :linenos: + + class C { + static invoke() { console.log("invoked") } + constructor() { console.log("constructed") } + } + let x = new C() // constructor is called + +The methods '*invoke*' and '*insantiate*' are similar but have differences as +discussed below. + +A :index:`compile-time error` occurs if a callable type contains both +the '*invoke*' and '*instantiate*' methods. + +| + +.. _Callable Types with Invoke Method: + +Callable Types with Invoke Method +================================= + +The method '*invoke*' can have an arbitrary signature. It can be +used in a *type call expression* in either case. +If the signature has parameters, then the call must contain corresponding +arguments. + +.. code-block:: typescript + :linenos: + + class Add { + static invoke(a: number, b: number): number { + return a + b + } + } + console.log(Add(2, 2)) // prints: 4 + +| + +.. _Callable Types with Instantiate Method: + +Callable Types with Instantiate Method +====================================== + +The method '*instantiate*' can have an arbitrary signature by itself. +If it is to be used in a *type call expression*, then its first parameter +must be a 'factory' (i.e., it must be a *parameterless function type +returning some class or struct type*). +The method can have or not have other parameters, and those parameters can +be arbitrary. + +In a *type call expression*, the argument corresponding to the 'factory' parameter is +passed implicitly: + +.. code-block:: typescript + :linenos: + + class C { + static instantiate(factory: () => C): C { + return factory() + } + } + let x = C() // factory is passed implicitly + + // Explicit call of 'instantiate' requires explicit 'factory': + let y = C.instantiate(() => { return new C()}) + +If the method '*instantiate*' has additional parameters, then the call must +contain corresponding arguments: + +.. code-block:: typescript + :linenos: + + class C { + name = "" + static instantiate(factory: () => C, name: string): C { + let x = factory() + x.name = name + return x + } + } + let x = C("Bob") // factory is passed implicitly + + +A :index:`compile-time error` occurs in a *type call expression* with type *T*, +if: + +- *T* has no method 'invoke' or 'instantiate'; or +- *T* has the method 'instantiate' but its first parameter is not a 'factory'. + +.. code-block:: typescript + :linenos: + + class C { + static instantiate(factory: string): C { + return factory() + } + } + let x = C() // compile-time error, wrong 'instantiate' 1st parameter + + +| + +.. _Additional Features: + +Additional Features +******************* + +| + +.. _Unary operator $$: + +Unary operator '$$' +=================== + +A prefix unary operator '$$' is used to pass primitive types by reference. +It is added to |LANG| to support the legacy ArkUI code. +As the use of this operator is deprecated, it is to be removed in the future +versions of the language. + +The operator '$$' can be followed by an identifier. The code '*$$this.a*' is +considered to be the same as '*$$ this.a*' and '*$$(this.a)*'. + + +| + +.. _Example of GUI Programming: + +Example of GUI Programming +************************** .. code-block:: typescript :linenos: @@ -907,7 +1063,7 @@ Example // delete found contact this.addrBook.contacts.splice(index, 1) - // determin new selectedPerson + // determine new selectedPerson index = (index < this.addrBook.contacts.length) ? index : index - 1 diff --git a/plugins/ets/doc/spec/17_experimental.rst b/plugins/ets/doc/spec/17_experimental.rst index 2f7ff8f5c..b99863544 100644 --- a/plugins/ets/doc/spec/17_experimental.rst +++ b/plugins/ets/doc/spec/17_experimental.rst @@ -275,10 +275,10 @@ An *array creation expression* creates an object that is a new array with the elements of the type specified by *typeReference*. The type of each *dimensionExpression* must be convertible (see -:ref:`Predefined Numeric Types Conversions`) to an integer type. +:ref:`Primitive Types Conversions`) to an integer type. A :index:`compile-time error` occurs otherwise. -A numeric conversion (see :ref:`Predefined Numeric Types Conversions`) is +A numeric conversion (see :ref:`Primitive Types Conversions`) is performed on each *dimensionExpression* to ensure that the resultant type is *int*. A :index:`compile-time error` occurs otherwise. @@ -1152,7 +1152,7 @@ Only *public* members can be accessed. this.member_2 // Compile-time error as member_2 is not accessible ... } - let a = new A + let a = new A() a.foo() // Ordinary class method is called a.bar() // Class extension function is called @@ -1196,7 +1196,7 @@ extension function* requires a variable as receiver. this.bar() // Compile-time error as instance extension functions are not acessible ... } - let a = new A + let a = new A() a.foo() // Ordinary class method is called a.bar() // Class instance extension function is called A.goo() // Static extension function is called @@ -1213,11 +1213,11 @@ derived class is found. function Base.foo () { console.log ("Base.foo is called") } function Derived.foo () { console.log ("Derived.foo is called") } - let b: Base = new Base + let b: Base = new Base() b.foo() // `Base.foo is called` to be printed - b = new Derived + b = new Derived() b.foo() // `Base.foo is called` to be printed - let d: Derived = new Derived + let d: Derived = new Derived() d.foo() // `Derived.foo is called` to be printed *Extension functions* can be: @@ -1256,7 +1256,7 @@ then calls to that name are routed to the method. foo () { console.log ("Method A.foo is called") } } function A.foo () { console.log ("Extension A.foo is called") } - let a = new A + let a = new A() a.foo() // Method is called, `Method A.foo is called` to be printed out The precedence between methods and *extension functions* can be expressed @@ -1282,11 +1282,11 @@ than that of type extension functions. function Base.foo () { console.log ("Extension Base.foo is called") } function Derived.foo () { console.log ("Extension Derived.foo is called") } - let b: Base = new Base + let b: Base = new Base() b.foo() // `Method Base.foo is called` to be printed - b = new Derived + b = new Derived() b.foo() // `Method Derived.foo is called` to be printed - let d: Derived = new Derived + let d: Derived = new Derived() d.foo() // `Method Derived.foo is called` to be printed If an *extension function* and another top-level function have the same name @@ -1300,7 +1300,7 @@ without a receiver as they have access to ``this``. class A { ... } function A.foo () { console.log ("Extension A.foo is called") } function foo () { console.log ("Top-level foo is called") } - let a = new A + let a = new A() a.foo() // Extension function is called, `Extension A.foo is called` to be printed out foo () // Top-level function is called, `Top-level foo is called` to be printed out @@ -1337,23 +1337,20 @@ Syntactically, the *trailing lambda* looks as follows: class A { foo (f: ()=>void) { ... } } - function foo (f: ()=>void) { ... } - let a = new A + let a = new A() a.foo() { console.log ("method lambda argument is activated") } // method foo receives last argument as an inline lambda - foo { console.log ("function lambda argument is activated") } - // function foo receives last argument as an inline lambda, - // () can be skipped as no other arguments are present - The formal syntax of the *trailing lambda* is presented below: .. code-block:: abnf trailingLambdaCall: - (objectReference '.' identifier typeArguments?) | (expression ('?.' | typeArguments)?) - arguments? block + ( objectReference '.' identifier typeArguments? + | expression ('?.' | typeArguments)? + ) + arguments block ; @@ -1378,9 +1375,8 @@ argument (see :ref:`Optional Parameters`). class A { foo (p?: ()=>void) { ... } } - function foo (p?: ()=>void) { ... } - let a = new A + let a = new A() a.foo() { console.log ("method lambda argument is activated") } // method foo receives last argument as an inline lambda @@ -1388,11 +1384,12 @@ argument (see :ref:`Optional Parameters`). // method 'foo' is called with 'p' parameter set to 'undefined' // ';' allows to specify expliclty that '{' starts the block + function bar(f: ()=>void) { ... } - foo() { console.log ("function lambda argument is activated") } - // function 'foo' receives last argument as an inline lambda, - foo(); { console.log ("that is the block code") } - // function 'foo' is called with 'p' parameter set to 'undefined' + bar() { console.log ("function lambda argument is activated") } + // function 'bar' receives last argument as an inline lambda, + bar(); { console.log ("that is the block code") } + // function 'bar' is called with 'p' parameter set to 'undefined' .. index:: trailing lambda @@ -1411,15 +1408,15 @@ argument (see :ref:`Optional Parameters`). function foo (f: ()=>void) { ... } function bar (n: number) { ... } - foo { console.log ("function lambda argument is activated") } + foo() { console.log ("function lambda argument is activated") } // function foo receives last argument as an inline lambda, - bar (5) { console.log ("after call to bar this block is executed") } + bar(5) { console.log ("after call of 'bar' this block is executed") } - foo (()=>{ console.log ("function lambda argument is activated") }) - { console.log ("after call to bar this block is executed") } + foo(() => { console.log ("function lambda argument is activated") }) + { console.log ("after call of 'foo' this block is executed") } /* here, function foo receives lambda as an argument and a block after - the call is just a block niot a trailing lambda. */ + the call is just a block, not a trailing lambda. */ | diff --git a/plugins/ets/doc/spec/1_intro.rst b/plugins/ets/doc/spec/1_intro.rst index 382049d6d..cd52442a5 100644 --- a/plugins/ets/doc/spec/1_intro.rst +++ b/plugins/ets/doc/spec/1_intro.rst @@ -25,16 +25,17 @@ multi-paradigm programming language called |LANG|. Common Description ****************** -The |LANG| language combines and supports many features that have been in use in -many well-known programming languages, and have proven useful and powerful tools. +The |LANG| language combines and supports features that are in use in many +well-known programming languages, where these tools have already proven +helpful and powerful. -|LANG| supports multiple programming paradigms as imperative, object-oriented, -functional and generic approaches, and combines them safely and consistently. +|LANG| supports imperative, object-oriented, functional, and generic +programming paradigms, and combines them safely and consistently. At the same time, |LANG| does not support features that allow software -developers to write dangerous, unsafe and inefficient code. In particular, +developers writing dangerous, unsafe, or inefficient code. In particular, the language uses the strong static typing principle that allows no dynamic -type changes as object types are determined by their declarations and checked +type changes, as object types are determined by their declarations and checked for semantic correctness at compile time. The following major aspects characterize the |LANG| language as a whole: @@ -47,7 +48,7 @@ The following major aspects characterize the |LANG| language as a whole: implemented by classes, and virtual functions (class members) with a dynamically dispatched overriding mechanism. Common in many (if not all) modern programming languages, object orientation enables - powerful, flexible, safe, clear and adequate software design. + powerful, flexible, safe, clear, and adequate software design. .. index:: object @@ -60,16 +61,16 @@ The following major aspects characterize the |LANG| language as a whole: - Modularity - The |LANG| language supports the *component programming approach* which - presumes that software is designed and implemented as a composition - of compilation units. A compilation unit in |LANG| is a standalone, independently + The |LANG| language supports the *component programming approach*. It + presumes that software is designed and implemented as a composition of + compilation units. A compilation unit in |LANG| is a standalone, independently compiled package or module that combines various programming resources (types, - classes, functions and so on). Package may combine several modules into one - logically consistent compilation unit. A module or package communicate with other - compilation units by exporting all or some of its resources to, or importing from - other units. This feature provides a high quality software development - process and software maintainability, supports flexible software reuse and - efficient version control. + classes, functions, and so on). A package can combine several modules into a + single logically consistent compilation unit. A module or a package + communicates with other compilation units by exporting all or some of its + resources to, or importing from other units. This feature provides a + high-quality software development process and software maintainability, + while supporting flexible reuse of software, and efficient version control. .. index:: modularity @@ -81,14 +82,16 @@ The following major aspects characterize the |LANG| language as a whole: Some program entities in |LANG| can be *type-parameterized*. This means that an entity can represent a very high-level (abstract) concept, and providing more concrete information makes it specialized for a - particular use case. A classical illustration is the notion of a list - that represents the ‘idea’ of an abstract data structure. Providing - additional information (the type of list elements) can turn this - abstract notion into a concrete list. + particular use case. + + A classical illustration is the notion of a list that represents the + ‘idea’ of an abstract data structure. This abstract notion can be turned + into a concrete list by providing additional information (the type of + list elements). Supported by many programming languages, a similar feature (‘generics’ or ‘templates’) serves as the basis of the generic programming - paradigm, and enables making programs and program structures more + paradigm. It enables making programs and program structures more generic and reusable. .. index:: @@ -105,36 +108,37 @@ The following major aspects characterize the |LANG| language as a whole: |LANG| provides an efficient application development solution for a wide range of devices. The language ecosystem is a developer-friendly, uniform - programming environment for a range of popular platforms (cross-platform - development). It can generate optimized applications capable of operating + programming environment for a range of popular platforms (‘cross-platform + development’). It can generate optimized applications capable of operating under the limitations of lightweight devices, or realizing the full potential of any specific target hardware. .. index:: multi-targeting - + |LANG| is designed as a part of the modern language manifold. To provide an efficient and safely executable code, the language takes flexibility and power from TypeScript and its predecessor JavaScript, and the static typing principle from Java and Kotlin. -The |LANG|’ overall design keeps its syntax style similar to those languages, -and some of its important constructs are almost identical to theirs on purpose. +The overall design keeps the |LANG|’ syntax style similar to that of those +languages, and some of its important constructs are almost identical to theirs +on purpose. In other words, there is a significant *common subset* of features of |LANG| -on the one hand, and of TypeScript, JavaScript, Java and Kotlin on the other. +on the one hand, and of TypeScript, JavaScript, Java, and Kotlin on the other. Consequently, the |LANG|’ style and constructs are no puzzle for the TypeScript and Java users who can sense the meaning of most constructs of the new language even if not understand them completely. -This stylistic and semantic similarity permits migrating the applications, -originally written in TypeScript, Java or Kotlin, smoothly to |LANG|. +This stylistic and semantic similarity permits migrating the applications +originally written in TypeScript, Java, or Kotlin smoothly to |LANG|. Like its predecessors, |LANG| is a relatively high-level language. It means that the language provides no access to low-level machine representations. -As a high-level language, |LANG| supports automatic storage management: -dynamically created objects are deallocated automatically soon after they -are no longer available, and deallocating them explicitly is not required. +As a high-level language, |LANG| supports automatic storage management +(dynamically created objects are deallocated automatically soon after they +are no longer available; deallocating them explicitly is not required). |LANG| is not merely a language, but rather a comprehensive software development ecosystem that facilitates the creation of software solutions @@ -159,17 +163,17 @@ Lexical and Syntactic Notation ****************************** This section introduces the notation (known as *context-free grammar*) -that this specification uses to define the lexical and syntactic +used in this specification to define the lexical and syntactic structure of a program. .. index:: context-free grammar The |LANG| lexical notation defines a set of productions (rules) that specify -the structure of the elementary language parts called tokens. All tokens are +the structure of the elementary language parts called 'tokens'. All tokens are defined in :ref:`Lexical Elements`. The set of tokens (identifiers, keywords, numbers/numeric literals, operator signs, delimiters), special characters -(white spaces and line separators) and comments comprises the language’s +(white spaces and line separators), and comments comprises the language’s *alphabet*. .. index:: @@ -204,8 +208,8 @@ describes how sequences of tokens can form syntactically correct programs. nonterminal Lexical and syntactic grammars are defined as a range of productions, -each comprised of an abstract symbol (*nonterminal*) as its *left-hand -side* and a sequence of one or more non-terminal and *terminal* symbols +each comprised of an abstract symbol (*nonterminal*) as its left-hand +side, and a sequence of one or more *nonterminal* and *terminal* symbols as its *right-hand side*. Each production includes the ':' character as a separator between the left-hand and the right-hand sides, and the ';' character as its end marker. @@ -214,7 +218,7 @@ character as its end marker. lexical grammar syntactic grammar abstract symbol - non-terminal symbol + nonterminal symbol terminal symbol character separator @@ -222,9 +226,9 @@ character as its end marker. Grammars draw the terminal symbols from a fixed width form. Starting from the :index:`goal symbol`, grammars specify the language itself, i.e., the set of -possible sequences of terminal symbols that can result from repeatedly -replacing any nonterminal in the sequence for a right-hand side of the -production, to which that nonterminal is the left-hand side. +possible sequences of terminal symbols that can result from repeatedly replacing +any nonterminal in the left-hand-side sequence for a right-hand side of the +production. .. index:: goal symbol @@ -233,14 +237,14 @@ production, to which that nonterminal is the left-hand side. Grammars can use the following additional symbols---sometimes called metasymbols---in the right-hand side of a grammar production along -with terminal and non-terminal symbols: +with terminal and nonterminal symbols: - Vertical line '\|' to specify alternatives. -- Question mark '?' to specify the optional (zero- or one-time) appearance - of the preceding terminal or non-terminal. +- Question mark '?' to specify the optional (zero- or one-time) occurrence + of the preceding terminal or nonterminal. -- Asterisk '\*' to mark a *terminal* or *non-terminal* that can appear zero +- Asterisk '\*' to mark a *terminal* or *nonterminal* that can occur zero or more times. - Brackets '(' and ')' to enclose any sequence of terminals and/or @@ -250,14 +254,13 @@ with terminal and non-terminal symbols: terminal terminal symbol nonterminal - non-terminal symbol goal symbol metasymbol grammar production Such additional symbols specify the structuring rules for terminal and -non-terminal sequences, but are not part of the terminal symbol sequences -that comprise the resultant program text. +nonterminal sequences. However, they are not part of the terminal symbol +sequences that comprise the resultant program text. The production below is an example that specifies a list of expressions: @@ -268,7 +271,7 @@ The production below is an example that specifies a list of expressions: ; This production introduces the following structure defined by the -non-terminal ``expressionList``: the expression list must consist of the +nonterminal ``expressionList``: the expression list must consist of the sequence of *expression*\ s separated by the ‘,’ terminal symbol. The sequence must have at least one *expression*, and the list is optionally terminated by the ‘,’ terminal symbol. @@ -285,9 +288,9 @@ Terms and Definitions ********************* This section contains the alphabetical list of important terms found in the -Specification with their |LANG|-specific definitions. Such definitions are +Specification, and their |LANG|-specific definitions. Such definitions are not generic and can differ significantly from the definitions of same terms -as used in other languages, application areas or industries. +as used in other languages, application areas, or industries. .. glossary:: :sorted: @@ -299,23 +302,28 @@ as used in other languages, application areas or industries. the order of calculation is determined by operator preferences. operator (in programming languages) - -- (1) token that denotes the action to be performed on a value (addition, - subtraction, comparisons, etc.). (2) a syntactic construct that denotes - an elementary calculation within an expression. Normally, an operator - consists of an operator sign and of one or more operands. + -- the term can have several meanings. + + (1) token that denotes the action to be performed on a value (addition, + subtraction, comparisons, etc.). + + (2) a syntactic construct that denotes an elementary calculation within + an expression. Normally, an operator consists of an operator sign and + one or more operands. In unary operators that have a single operand, the operator sign can be placed either in front of an operand (*prefix* unary operator), or after - the operand (*postfix* unary operator). If two operands are available, - then the operator sign can be placed between two operands (*infix* - binary operator). A conditional operator with three operands is called - *ternary*. + the operand (*postfix* unary operator). + + If both operands are available, then the operator sign can be placed + between the two (*infix* binary operator). A conditional operator with + three operands is called *ternary*. Some operators have special notations; for example, the indexing operator, while formally being a binary operator, has a conventional form like a[i]. - Some languages treat operators as “syntactic sugar”---a conventional + Some languages treat operators as 'syntactic sugar'---a conventional version of a more common construct, i.e., *function call*. Therefore, an operator like ``a+b`` is conceptually treated as the call ``+(a,b)``, where the operator sign plays the role of the function name, and the @@ -333,21 +341,21 @@ as used in other languages, application areas or industries. -- an argument of an operation. Syntactically, operands have the form of simple or qualified identifiers that refer to variables or members of structured objects. In turn, operands can be operators whose preferences - (“priorities”) are higher that the preference of the given operator. + ('priorities') are higher than the preference of the given operator. operation - -- the informal notion that means an action, or a process of operator + -- the informal notion that means an action or a process of operator evaluation. metasymbol - -- additional symbols '\|', '?', '\*', '(' and ')' that can be used - along with terminal and non-terminal symbols in the right-hand side + -- additional symbols '\|', '?', '\*', '(', and ')' that can be used + along with terminal and nonterminal symbols in the right-hand side of a grammar production. goal symbol -- sentence that consists of a single distinguished nonterminal - (*compilationUnit*) and describes how sequences of tokens can form - syntactically correct programs. + (*compilationUnit*). The *goal symbol* describes how sequences of + tokens can form syntactically correct programs. token -- an elementary part of a programming language: identifier, keyword, @@ -369,8 +377,8 @@ as used in other languages, application areas or industries. -- representation of a certain value type. comment - -- a piece of text, insignificant for the syntactic grammar, added to - the stream in order to document and compliment the source code. + -- a piece of text, insignificant for the syntactic grammar, that is + added to the stream in order to document and compliment the source code. primitive type -- numeric value types, character, and boolean value types whose names @@ -380,13 +388,13 @@ as used in other languages, application areas or industries. -- named type (class or interface) that has type parameters. generic - see *generic type*. + -- see *generic type*. non-generic type -- named type (class or interface) that has no type parameters. non-generic - see *non-generic type*. + -- see *non-generic type*. type reference -- references that refer to named types by specifying their type names, @@ -394,8 +402,8 @@ as used in other languages, application areas or industries. parameters of the named type. nullable type - -- variable declared to have the null value, or type T | null that can - hold values of type T and its derived types. + -- variable declared to have the value *null*, or `type T | null` that can + hold values of type *T* and its derived types. nullish value -- reference which is null or undefined. @@ -417,15 +425,15 @@ as used in other languages, application areas or industries. introducing a named function. terminal symbol - -- a syntactically invariable token, i.e. a syntactic notation defined - directly by the invariable form of the lexical grammar that defines a - set of productions starting from the :term:`goal symbol`. + -- a syntactically invariable token (i.e., a syntactic notation defined + directly by an invariable form of the lexical grammar that defines a + set of productions starting from the :term:`goal symbol`). terminal -- see *terminal symbol*. - non-terminal symbol - -- token that is syntactically variable and is the result of successive + nonterminal symbol + -- syntactically variable token that results from the successive application of the production rules. context-free grammar @@ -433,7 +441,7 @@ as used in other languages, application areas or industries. of only a single nonterminal symbol. nonterminal - -- see *non-terminal symbol*. + -- see *nonterminal symbol*. keyword -- one of the *reserved words* that have their meanings permanently @@ -455,16 +463,16 @@ as used in other languages, application areas or industries. grammar -- set of rules that describe what possible sequences of terminal and - non-terminal symbols a programming language interepretes as correct. + nonterminal symbols a programming language interepretes as correct. - A grammar is a range of productions, each production comprised of an + Grammar is a range of productions. Each production comprises an abstract symbol (nonterminal) as its left-hand side, and a sequence - of non-terminal and terminal symbols as its right-hand side. - Each grammatical production has the character ‘:’ to separate its left- + of nonterminal and terminal symbols as its right-hand side. + Each production has the character ‘:’ as a separator between the left-hand and right-hand sides, and the character ‘;’ as the end marker. production - -- a sequence of terminal and non-terminal symbols that a programming + -- a sequence of terminal and nonterminal symbols that a programming language interpretes as correct. white space @@ -510,54 +518,56 @@ as used in other languages, application areas or industries. handle any exception or error that is not handled by a preceding clause. overloading - -- situation where different imported functions, or a function(s) of - the current module and an imported function(s) have the same name but + -- situation where different imported functions, or a function of + the current module and an imported function have the same name but different signatures. shadowing - -- situation where a function(s) of the current module and an imported - function(s) have the same name and signature; shadowing causes a - compile-time error where function declarations are are duplicated, i.e. + -- situation where a function of the current module and an imported + function have the same name and signature. Shadowing causes a + compile-time error where function declarations are duplicated (i.e., the name and override-equivalent signatures of an imported function are - the same as those of a function declared in the current compilation unit. + the same as those of a function declared in the current compilation unit). package level scope -- name that is declared on the package level, and accessible throughout the entire package and in other packages if exported. module level scope - -- name that is applicable for separate modules only, and accessible + -- name that is applicable for separate modules only. It is accessible throughout the entire module and in other packages if exported. class level scope - -- name declared inside a class, and accessible inside and sometimes---by + -- name declared inside a class. It is accessible inside and sometimes---by means of an access modifier, or via a derived class---outside that class. interface level scope - -- name declared inside an interface, and accessible inside and outside + -- name declared inside an interface. It is accessible inside and outside that interface. enum level scope - -- scope of enumeration that defines a type inside a package or module, - and is identical to a corresponding package or module level scope. An - enumeration constant scope is identical to the enumeration itself. + -- scope of enumeration that defines a type inside a package or module. + Enum level scope is identical to a corresponding package or module level + scope. An enumeration constant scope is identical to the enumeration + itself. function parameter scope - -- scope of a type parameter name in a function declaration, that is + -- scope of a type parameter name in a function declaration. It is identical to that entire declaration. method scope -- scope of a name declared immediately inside the body of a method - (function) declaration, that is identical to the body of that method - (function) declaration from the place of declaration, and up to the - end of the body. + (function) declaration. Method scope is identical to the body of that + method (function) declaration from the place of declaration, and up to + the end of the body. function scope -- same as *method scope*. type parameter scope - -- name of atype parameter declared in a class or an interface, that - is identical to that entire declaration (except static member declarations). + -- name of a type parameter declared in a class or an interface. The type + parameter scope is identical to the entire declaration (except static + member declarations). static member -- a constant variable (variable of a primitive type, or type *String*) diff --git a/plugins/ets/doc/spec/2_lexical.rst b/plugins/ets/doc/spec/2_lexical.rst index 39cc410e6..13037129a 100644 --- a/plugins/ets/doc/spec/2_lexical.rst +++ b/plugins/ets/doc/spec/2_lexical.rst @@ -57,7 +57,7 @@ Lexical Input Elements frontend_status: Done The language has lexical input elements of the following types: -:ref:`White Spaces`, :ref:`Line Separators`, :ref:`Tokens` and :ref:`Comments`. +:ref:`White Spaces`, :ref:`Line Separators`, :ref:`Tokens`, and :ref:`Comments`. | @@ -83,9 +83,9 @@ White spaces include the following: - Form feed (U+000C), -- No-break space (U+00A0), +- No-break space (U+00A0), and -- Zero width no-break space (U+FEFF). +- Zero-width no-break space (U+FEFF). White spaces can occur within comments but not within any kind of token. @@ -107,7 +107,7 @@ Line Separators frontend_status: Done Line separators are lexical input elements that divide sequences of Unicode -input characters into lines and separate tokens from one another to improve +input characters into lines, and separate tokens from one another to improve the source code readability. Line separators include the following: @@ -116,7 +116,7 @@ Line separators include the following: - Carriage return character (U+000D or ASCII ), -- Line separator character (U+2028 or ASCII ), +- Line separator character (U+2028 or ASCII ), and - Paragraph separator character (U+2029 or ASCII ). @@ -136,13 +136,13 @@ Tokens form the vocabulary of the language. There are four classes of tokens: :ref:`Identifiers`, :ref:`Keywords`, :ref:`Operators and Punctuators`, and :ref:`Literals`. -Token is the only lexical input element which can act as a terminal symbol +Token is the only lexical input element that can act as a terminal symbol of the syntactic grammar. In the process of tokenization, the next token is always the longest sequence of characters that form a valid token. White -spaces (see :ref:`White spaces`) are ignored except when they separate +spaces (see :ref:`White spaces`) are ignored, except when they separate tokens that would otherwise merge into a single token. -In many cases line separators are treated as white spaces except where line +In many cases line separators are treated as white spaces, except where line separators have special meanings. See :ref:`Semicolons` for more details. .. index:: @@ -179,8 +179,8 @@ specified by the Unicode Standard. The first character in an identifier must be '\$', '\_', or any Unicode code point with the Unicode property 'ID_Start'[2]_. Other characters must be Unicode code points with the Unicode property, or one of the following -characters: '\$' (\\U+0024), 'Zero Width Non-Joiner' (, \\U+200C) or -'Zero Width Joiner' (, \\U+200D). +characters: '\$' (\\U+0024), 'Zero-Width Non-Joiner' (, \\U+200C), or +'Zero-Width Joiner' (, \\U+200D). .. index:: identifier @@ -226,7 +226,7 @@ Keywords *Keywords* are the reserved words that have permanently predefined meanings in the language. -The following keywords are reserved in any context (*hard keywords*) and +The following keywords are reserved in any context (*hard keywords*), and cannot be used as identifiers: .. index:: @@ -303,7 +303,7 @@ not otherwise restricted: | char | long | undefined | | +---------------+---------------+---------------+---------------+ -The following identifiers are also treated as keywords and are reserved for +The following identifiers are also treated as keywords reserved for the future use (or used in TS): .. index:: @@ -329,12 +329,12 @@ Operators and Punctuators frontend_status: Partly todo: note: ?? and ?. are not implemented yet -*Operators* are tokens that denote various actions on values. Examples are -addition, subtraction, comparisons and others. +*Operators* are tokens that denote various actions to be performed on values. +The examples are addition, subtraction, comparisons, and other. -*Punctuators* are tokens that serve for separating, completing or otherwise -organizing program elements and parts. The examples are commas, semicolons, -parentheses, square brackets, etc. +*Punctuators* are tokens used to separate, complete, or otherwise organize +program elements and parts. The examples are commas, semicolons, parentheses, +square brackets, etc. The following character sequences represent operators and punctuators: @@ -394,7 +394,7 @@ Integer Literals *Integer literals* represent numbers that do not have a decimal point or an exponential part. Integer literals can be written with bases 16 -(hexadecimal), 10 (decimal), 8 (octal) and 2 (binary). +(hexadecimal), 10 (decimal), 8 (octal), and 2 (binary). .. index:: integer @@ -442,11 +442,11 @@ Examples: 0o777 // octal literal 0b101 // binary literal -The underscore character '_' can be used after a base prefix or between -successive digits in order to denote an integer literal and improve -readability. Underscore characters in such positions do not change the -values of literals. However, an underscore character must not be used as -the very first and the very last symbol of an integer literal. +The underscore character '_' after a base prefix or between successive +digits can be used to denote an integer literal and improve readability. +Underscore characters in such positions do not change the values of literals. +However, an underscore character must not be the very first or the very last +symbol of an integer literal. .. index:: prefix @@ -484,17 +484,18 @@ Floating-Point Literals frontend_status: Partly todo: let d = 9999.0009E-9994 --> Inf, but should be 0 todo: let d = 4.9e-324; (in stdlib Double.ets) --> Inf, but should be 0x000000000000001 double + todo: 'f' suffix *Floating-point literals* represent decimal numbers and consist of a -whole-number part, a decimal point, a fraction part and -an exponent. +whole-number part, a decimal point, a fraction part, +an exponent, and a float type suffix. .. code-block:: abnf FloatLiteral: - DecimalIntegerLiteral '.' FractionalPart? ExponentPart? - | '.' FractionalPart ExponentPart? - | DecimalIntegerLiteral ExponentPart + DecimalIntegerLiteral '.' FractionalPart? ExponentPart? FloatTypeSuffix? + | '.' FractionalPart ExponentPart? FloatTypeSuffix? + | DecimalIntegerLiteral ExponentPart FloatTypeSuffix? ; ExponentPart: @@ -505,6 +506,9 @@ an exponent. [0-9] | [0-9] [0-9_]* [0-9] ; + FloatTypeSuffix: + 'f' + ; Examples: @@ -512,20 +516,27 @@ Examples: :linenos: 3.14 + 3.14f 3.141_592 .5 1e10 + 1e10f -In order to denote a floating-point literal, the underscore character '\_' can -be used after a base prefix or between successive digits for readability. +The underscore character '\_' after a base prefix or between successive digits +can be used to denote a floating-point literal and improve readability. Underscore characters in such positions do not change the values of literals. -However, the underscore character must not be used as the very first and very +However, an underscore character must not be the very first and the very last symbol of an integer literal. -A floating-point literal is of type *double* (the type *number* is -an alias to *double*). In variable and constant declarations, a -floating-point literal can be implicitly converted to type *float* -(see :ref:`Type Compatibility with Initializer`). +A floating-point literal is of type *float* if *float type suffix* is present +and is of type *double* otherwise (type *number* is an alias to +*double*). + +A :index:`compile-time error` occurs if a non-zero floating-point literal is too large for its type. + +A floating-point literal in variable and constant declarations +can be implicitly converted to type *float* (see +:ref:`Type Compatibility with Initializer`). .. index:: floating-point literal @@ -545,8 +556,8 @@ BigInt Literals frontend_status: None *BigInt literals* represent integer numbers with unlimited number of digits. -BigInt literals use decimal base only. It is a sequence of digits which ends -with the symbol 'n'. +BigInt literals use decimal base only. A BigInt literal is a sequence of +digits followed by the symbol 'n'. .. code-block:: abnf @@ -562,23 +573,22 @@ Examples: 153n // bigint literal 1_153n // bigint literal -The underscore character '_' can be used between successive digits in order -to denote a bigint literal and improve readability. Underscore characters in +The underscore character '_' used between successive digits can be used to +denote a BigInt literal and improve readability. Underscore characters in such positions do not change the values of literals. However, an underscore -character must not be used as the very first and the very last symbol -of a bigint literal. +character must not be the very first and the very last symbol of a BigInt +literal. BigInt literals are always of type *bigint*. -Built-in functions as shown below +Strings that represent numbers or any integer values can be converted to +*bigint* by using the built-in functions. See the example below: .. code-block:: typescript BigInt (other: string): bigint BigInt (other: long): bigint -allow converting strings that represent numbers, or any integer values into -*bigint* ones. .. index:: integer @@ -586,9 +596,9 @@ allow converting strings that represent numbers, or any integer values into underscore character static function -Two other static functions allow to take *bitsCount* lower bits of the +Two other static functions allow taking *bitsCount* lower bits of a BigInt number and return them as a result. Signed and unsigned versions -are available: +are possible: .. code-block:: typescript @@ -605,7 +615,7 @@ Boolean Literals .. meta: frontend_status: Done -There are two *Boolean literal* values represented by the keywords +The two *Boolean literal* values are represented by the keywords ``true`` and ``false``. .. code-block:: abnf @@ -636,7 +646,7 @@ String Literals single or double quotes. A special form of string literals is *template literal* (see :ref:`Template Literals`). -String literals are of type *string*, which is a predefined reference +String literals are of type *string*. Type *string* is a predefined reference type (see :ref:`String Type`). .. index:: @@ -644,6 +654,8 @@ type (see :ref:`String Type`). template literal predefined reference type +| + .. code-block:: abnf StringLiteral: @@ -673,9 +685,9 @@ Normally, characters in string literals represent themselves. However, certain non-graphic characters can be represented by explicit specifications or Unicode codes. Such constructs are called *escape sequences*. -Graphic characters within a string literal, e.g., single quotes '``'``', double -quotes '``"``', backslashes '``\``' and some others, can also be represented by -escape sequences. +Escape sequences can represent graphic characters within a string literal, e.g., +single quotes '``’``', double quotes '``”``', backslashes '``\``', and some +others. .. index:: string literal @@ -687,9 +699,13 @@ escape sequences. An escape sequence always starts with the backslash character '``\``', followed by one of the following characters: -- ``"`` (double quote, U+0022) +- ``”`` (double quote, U+0022) + +.. " + +- ``'`` (neutral single quote, U+0027) -- ``'`` (single quote, U+0027) +.. ’ U+2019 - ``b`` (backspace, U+0008) @@ -703,18 +719,18 @@ by one of the following characters: - ``v`` (vertical tab, U+000b) -- ``\\`` (backslash, U+005c) +- ``\`` (backslash, U+005c) - ``x`` and two hexadecimal digits, like ``7F`` -- ``u`` and four hexadecimal digits, forming fixed Unicode escape - sequence, like ``\u005c`` +- ``u`` and four hexadecimal digits, forming a fixed Unicode escape + sequence like ``\u005c`` - ``u{`` and at least one hexadecimal digit, followed by ``}``, forming - a bounded Unicode escape sequence, like ``\u{5c}`` + a bounded Unicode escape sequence like ``\u{5c}`` -- any single character, except digits from ‘1’ to ‘9’ and characters - ‘x’, ‘u’, CR and LF. +- any single character except digits from ‘1’ to ‘9’ and characters ‘x’, + ‘u’, CR, and LF. Examples: @@ -769,7 +785,7 @@ evaluated at compile time. The evaluation of a template string is called See :ref:`String Interpolation Expressions` for the grammar of *embeddedExpression*. -An example of a multi-line string is below: +Below is an example of a multi-line string: .. code-block:: typescript :linenos: @@ -792,8 +808,8 @@ Null Literal .. meta: frontend_status: Partly -There is only one literal (called *null literal*) that denotes a reference -without pointing at any entity. It is represented by the keyword ``null``. +'*Null literal*' is the only literal to denote a reference without pointing +at any entity. It is represented by the keyword ``null``. .. code-block:: abnf @@ -801,8 +817,8 @@ without pointing at any entity. It is represented by the keyword ``null``. 'null' ; -The null literal denotes the null reference which represents an absence -of a value, and is a valid value only for types *T* | ``null``, (see +The *null literal* denotes the null reference that represents an absence +of a value, and is a valid value only for types ``T | null`` (see :ref:`Nullish Types`). The null literal is of type *null* (see :ref:`null Type`) and is, by definition, the only value of this type. @@ -819,9 +835,10 @@ of a value, and is a valid value only for types *T* | ``null``, (see Undefined Literal ======================== -There is only one literal (called *undefined literal*) that denotes a reference -with a value that is not defined. It is the only value of type *undefined* -(see :ref:`undefined Type`), and is represented by the keyword ``undefined``. +'*Undefined literal*' is the only literal to denote a reference with a value +that is not defined. '*Undefined literal*' is the only value of type +*undefined* (see :ref:`undefined Type`). It is represented by the keyword +``undefined``. .. code-block:: abnf @@ -845,8 +862,8 @@ Comments frontend_status: Partly todo: Q: "Comments may be nested" - do we need nested multiline comments? It is not yet supported -A piece of text added in the stream to document and compliment the source -code is a *Comment*. Comments are insignificant for the syntactic grammar. +*Comment* is a piece of text added in the stream to document and compliment +the source code. Comments are insignificant for the syntactic grammar. *Line comments* start with the character sequence '//' and stop at the end of the line. diff --git a/plugins/ets/doc/spec/3_types.rst b/plugins/ets/doc/spec/3_types.rst index c515c5676..06c8e005e 100644 --- a/plugins/ets/doc/spec/3_types.rst +++ b/plugins/ets/doc/spec/3_types.rst @@ -18,15 +18,15 @@ Types .. meta: frontend_status: Partly -|LANG| is a statically typed language, and the type of every declared entity +|LANG| is a statically typed language, i.e., the type of every declared entity and every expression is known at compile time because it is either set explicitly by a developer, or inferred implicitly by the compiler. There are two categories of types: -#. *value types* (see :ref:`Value Types`), and +#. *Value types* (see :ref:`Value Types`), and -#. *reference types* (see :ref:`Reference Types`). +#. *Reference types* (see :ref:`Reference Types`). The types integral to |LANG| are called *predefined types* (see :ref:`Predefined Types`). @@ -34,7 +34,7 @@ The types integral to |LANG| are called *predefined types* (see The types introduced, declared, and defined by a developer are called *user-defined types*. All *user-defined types* must always have a complete type definition -presented as source code in |LANG| language. +presented as source code in |LANG|. .. index:: statically typed language @@ -61,7 +61,7 @@ Predefined Types todo: unsigned types are not supported yet todo: void type is not supported yet(void as reference type) -The set of the predefined types includes the following: +Predefined types include the following: - Basic numeric value type: ``number`` @@ -72,19 +72,21 @@ The set of the predefined types includes the following: - Character value type: ``char`` -- Predefined reference string type: ``string`` +- Reference string type: ``string`` -- Predefined reference BigInt type: ``bigint`` +- Reference array type: ``[]`` -- Predefined class types: ``Object``, ``String``, ``never``, and ``void`` +- Reference BigInt type: ``bigint`` -- Each predefined value type corresponds to a predefined class type that wraps - the value type: ``Number``, ``Byte``, ``Short``, ``Int``, ``Long``, - ``Float``, ``Double``, ``Char``, and ``Boolean``. +- Class types: ``Object``, ``String``, ``Array``, ``never``, and ``void`` +Each predefined value type corresponds to a predefined class type that wraps +the value type: ``Number``, ``Byte``, ``Short``, ``Int``, ``Long``, +``Float``, ``Double``, ``Char``, and ``Boolean``. + The numeric value types, character, and boolean value types are called -*primitive types*. Primitive type names are reserved, and cannot be used +*primitive types*. Primitive type names are reserved; they cannot be used for user-defined type names. Type ``double`` is an alias to ``number``; type ``Double`` is an alias @@ -113,7 +115,7 @@ User-Defined Types .. meta: frontend_status: Partly -The *user-defined* types include the following: +*User-defined* types include the following: - Class types (see :ref:`Classes`); - Interface types (see :ref:`Interfaces`); @@ -158,10 +160,11 @@ The following table summarizes all |LANG| types: | ``int``, ``long``, | ``Int``, ``Long``, | | array types, | | ``float``, ``double``, | ``Float``, ``Double``, | | function types, | | ``char``, ``boolean`` | ``Char``, ``Boolean``, | | tuple types, | -| | ``Object``, ``never``, | | union types, | +| | ``Object``, ``object``, | | union types, | | | ``void``, ``null``, | | type parameters | -| | ``bigint``, ``string``, | | | -| | ``BigInt``, ``String`` | | | +| | ``String``, ``string``, | | | +| | ``BigInt``, ``bigint``, | | | +| | ``never`` | | | +-------------------------+-------------------------+----------------+------------------+ .. index:: @@ -203,6 +206,8 @@ The following can refer to a type in a source code: function type union type +| + .. code-block:: abnf type: @@ -227,7 +232,7 @@ Example: Parentheses in types (where a type is a combination of array, function, or union types) are used to specify the required type structure. -Without parentheses, the symbol ``'|'`` that constructs a union type +Without parentheses, the symbol '``|``' that constructs a union type has the lowest precedence. .. index:: @@ -275,17 +280,17 @@ Named Types .. meta: frontend_status: Done -Classes, interfaces, enumerations, and unions are the named types that are +Classes, interfaces, enumerations, and unions are named types that are introduced by class declarations (see :ref:`Classes`), interface declarations (see :ref:`Interfaces`), enumeration declarations (see :ref:`Enumerations`), and union declarations (see :ref:`Union Types`) respectively. -Classes and interfaces that have type parameters are *generic types* +Classes and interfaces with type parameters are *generic types* (see :ref:`Generics`). Named types without type parameters are *non-generic types*. -The *type references* (see :ref:`Type References`) refer to named types by +*Type references* (see :ref:`Type References`) refer to named types by specifying their type names, and (where applicable) type arguments to be substituted for the type parameters of the named type. @@ -318,9 +323,9 @@ A type reference uses a type name (either *simple* or *qualified*, see :ref:`Names`), or a type alias (see :ref:`Type Alias Declaration`) to refer to a type. -Optionally, each identifier in the name or alias can be followed by type -arguments (see :ref:`Type Arguments`) if the referred type is a class, or an -interface type. +Optionally, each identifier in a name or alias can be followed by type +arguments (see :ref:`Type Arguments`) if the referred type is a class +or an interface type. .. index:: type reference @@ -358,12 +363,11 @@ Value Types frontend_status: Partly todo: minor issue/feature - float/double literal parser in libc/libstdc++ can't parse everything, eg: 4.9E-324 -The predefined type (see :ref:`Floating-Point Types and Operations`), integer -types (see :ref:`Integer Types and Operations`), floating-point types (see -:ref:`Floating-Point Types and Operations`), the boolean type (see -:ref:`Boolean Types and Operations`), the character type (see -:ref:`Character Types and Operations`), and user-defined enumeration types (see -:ref:`Enumerations`) are *value types*. +The predefined integer types (see :ref:`Integer Types and Operations`), +floating-point types (see :ref:`Floating-Point Types and Operations`), the +boolean type (see :ref:`Boolean Types and Operations`), the character type +(see :ref:`Character Types and Operations`), and user-defined enumeration +types (see :ref:`Enumerations`) are *value types*. Such types’ values do *not* share state with other values. @@ -400,14 +404,14 @@ Integer Types and Operations | ``bigint``| All integers with no limits | ``BigInt`` | +-----------+--------------------------------------------------------------------+--------------------------+ -|LANG| provides a number of operators to act on integer values: +|LANG| provides a number of operators to act on integer values as listed below. - Comparison operators that produce a value of type *boolean*: + Numerical comparison operators '<', '<=', '>', and '>=' (see :ref:`Numerical Comparison Operators`); + Numerical equality operators '==' and '!=' (see :ref:`Value Equality Operators`); -- Numerical operators that produce a value of type ``int`` or ``long``: +- Numerical operators that produce a value of type ``int``, ``long``, or ``bigint``: + Unary plus '+' and minus '-' operators (see :ref:`Unary Plus` and :ref:`Unary Minus`); + Multiplicative operators '\*', '/', and '%' (see :ref:`Multiplicative Expressions`); @@ -422,11 +426,11 @@ Integer Types and Operations + Integer bitwise operators '&', '^', and '\|' (see :ref:`Integer Bitwise Operators`); - Conditional operator '?:' (see :ref:`Conditional Expressions`); -- Cast operator (see :ref:`Cast Expressions`), which converts an integer - value to a value of any specified numeric type; -- The string concatenation operator '+' (see :ref:`String Concatenation`), - which (if a ``string`` operand and an integer operand are both available) - converts the integer operand to a ``string`` (the character of a ``char`` +- Cast operator (see :ref:`Cast Expressions`) that converts an integer value + to a value of any specified numeric type; +- String concatenation operator '+' (see :ref:`String Concatenation`) that, if + a ``string`` operand and an ``integer`` operand are both available, converts + the integer operand to a ``string`` (the character of a ``char`` operand, or the decimal form of a ``byte``, ``short``, ``int``, or ``long`` operand), and then creates a concatenation of two strings as a new ``string``. @@ -476,11 +480,11 @@ Integer Types and Operations operand The classes ``Byte``, ``Short``, ``Int``, and ``Long`` also predefine other -constructors, methods and constants that are part of the |LANG| standard +constructors, methods, and constants that are parts of the |LANG| standard library (see :ref:`Standard Library`). If one operand is not ``long``, then the numeric promotion (see -:ref:`Predefined Numeric Types Conversions`) must be used first to widen +:ref:`Primitive Types Conversions`) must be used first to widen it to type ``long``. If no operand is of type ``long``, then: @@ -504,8 +508,8 @@ An integer operator can throw errors (see :ref:`Errors Handling`) as follows: integer remainder operator '%' (see :ref:`Remainder`) throw the ``ArithmeticError`` if their right-hand operand is zero. - An increment operator '++' and a decrement operator '--' (see - :ref:`Additive Expressions`) throw the ``OutOfMemoryError`` if boxing - conversion (see :ref:`Predefined Numeric Types Conversions`) is required + :ref:`Additive Expressions`) throw the *OutOfMemoryError* if boxing + conversion (see :ref:`Primitive Types Conversions`) is required but the available memory is not sufficient to perform it. .. index:: @@ -548,18 +552,21 @@ Floating-Point Types and Operations .. meta: frontend_status: Partly -+-------------+--------------------------------------------------------+--------------------------+ -| Type | Type's Set of Values | Corresponding Class Type | -+=============+========================================================+==========================+ -| ``float`` | The set of all IEEE-754 32-bit floating-point numbers | ``Float`` | -+-------------+--------------------------------------------------------+--------------------------+ -| ``number``, | The set of all IEEE-754 64-bit floating-point numbers | ``Number`` | -| ``double`` | | ``Double`` | -+-------------+--------------------------------------------------------+--------------------------+ ++-------------+-------------------------------------+--------------------------+ +| Type | Type's Set of Values | Corresponding Class Type | ++=============+=====================================+==========================+ +| ``float`` | The set of all IEEE-754 32-bit | ``Float`` | +| | floating-point numbers | | +| | floating-point numbers | | ++-------------+-------------------------------------+--------------------------+ +| ``number``, | The set of all IEEE-754 64-bit | ``Number`` | +| ``double`` | floating-point numbers | ``Double`` | ++-------------+-------------------------------------+--------------------------+ -A number of |LANG| operators act on the floating-point type values: +|LANG| provides a number of operators to act on floating-point type values as +listed below. -- Comparison operators that produce a type ``boolean`` value: +- Comparison operators that produce a value of type ``boolean``: - Numerical comparison operators '<', '<=', '>', and '>=' (see :ref:`Numerical Comparison Operators`); @@ -581,10 +588,10 @@ A number of |LANG| operators act on the floating-point type values: - Conditional operator '?:' (see :ref:`Conditional Expressions`); -- Cast operator (see :ref:`Cast Expressions`), which converts a floating-point +- Cast operator (see :ref:`Cast Expressions`) that converts a floating-point value to a value of any specified numeric type; -- The string concatenation operator '+' (see :ref:`String Concatenation`), - which (if both a ``string`` operand and a floating-point operand are present) +- The string concatenation operator '+' (see :ref:`String Concatenation`) that, + if both a ``string`` operand and a floating-point operand are present, converts the floating-point operand to a ``string`` with a value represented in the decimal form (without the loss of information), and then creates a concatenation of the two strings as a new ``string``. @@ -622,19 +629,19 @@ A number of |LANG| operators act on the floating-point type values: string The classes ``Float`` and ``Double``, and the math library also predefine other -constructors, methods and constants which are part of the |LANG| standard +constructors, methods, and constants that are parts of the |LANG| standard library (see :ref:`Standard Library`). -The operation is a floating-point operation if at least one of the operands in -a binary operator is of the floating-point type, even if the other operand is -integer. +An operation is called a *floating-point operation* if at least one of the +operands in a binary operator is of the floating-point type (even if the other +operand is integer). -If at least one operand of the numerical operator is of type ``double``, +If at least one operand of the numerical operator is of type ``double``, then the operation implementation uses 64-bit floating-point arithmetic, and the result of the numerical operator is a value of type ``double``. If the other operand is not ``double``, then the numeric promotion (see -:ref:`Predefined Numeric Types Conversions`) must be used first to widen it +:ref:`Primitive Types Conversions`) must be used first to widen it to type ``double``. If no operand is of type ``double``, then the operation implementation @@ -673,11 +680,11 @@ Operators on floating-point numbers (except the remainder operator, see :ref:`Remainder`) behave in compliance with the IEEE 754 Standard. For example, |LANG| requires the support of IEEE 754 *denormalized* floating-point numbers and *gradual underflow* that make it easier to prove -a particular numerical algorithms’ desirable properties. Floating-point +the desirable properties of a particular numerical algorithm. Floating-point operations do not '*flush to zero*' if the calculated result is a denormalized number. -|LANG| requires that floating-point arithmetic behave as if the floating-point +|LANG| requires floating-point arithmetic to behave as if the floating-point result of every floating-point operator is rounded to the result precision. An *inexact* result is rounded to the representable value nearest to the infinitely precise result; |LANG| uses the '*round to nearest*' principle (the default @@ -702,10 +709,10 @@ significant bit zero out of any two equally near representable values. denormalized number |LANG| uses '*round toward zero*' to convert a floating-point value to an -integer (see :ref:`Predefined Numeric Types Conversions`), which in this -case acts as if the number is truncated, and the mantissa bits discarded. -The format’s value closest to, and no greater in magnitude than the infinitely -precise result is chosen as the result of *rounding toward zero*. +integer (see :ref:`Primitive Types Conversions`) that in this case acts as +if the number is truncated, and the mantissa bits are discarded. +The result of *rounding toward zero* is the value of that format that is +closest to an no greater in magnitude than the infinitely precise result. A floating-point operation with overflow produces a signed infinity. @@ -720,7 +727,7 @@ All numeric operations with a NaN operand result in NaN. A floating-point operator (the increment '++' operator and decrement '--' operator, see :ref:`Additive Expressions`) can throw the *OutOfMemoryError* (see :ref:`Errors Handling`) if boxing conversion (see -:ref:`Predefined Numeric Types Conversions`) is needed but the available +:ref:`Primitive Types Conversions`) is needed but the available memory is not sufficient to perform it. .. index:: @@ -760,17 +767,17 @@ Numeric Types Hierarchies Integer types and floating-point types are the *numeric types*. -Larger types include smaller types (of their values): +Larger types include smaller types or their values: - ``double`` > ``float`` > ``long`` > ``int`` > ``short`` > ``byte`` - ``bigint`` > ``long`` > ``int`` > ``short`` > ``byte`` A smaller type’s value can be assigned to a larger type’s variable. -The type *bigint* is an exception because any integer value or some string -type values can be converted into *bigint* by using built-in functions -*BigInt(anyInteger: long): bigint* or -*BigInt(anyIntegerString: string): bigint*. +Type *bigint* is an exception because any integer value or some string type +values can be converted into *bigint* by using built-in functions +*BigInt(anyInteger: long): bigint*, or *BigInt(anyIntegerString: string): +bigint*. .. index:: numeric type @@ -811,9 +818,9 @@ The boolean operators are as follows: - Relational operators '==' and '!=' (see :ref:`Relational Expressions`); - Logical complement operator '!' (see :ref:`Logical Complement`); -- Logical operators '&', '^', and '|' (see :ref:`Integer Bitwise Operators`); +- Logical operators '&', '^', and '``|``' (see :ref:`Integer Bitwise Operators`); - Conditional-and operator '&&' (see :ref:`Conditional-And Expression`) and - conditional-or operator '||' (see :ref:`Conditional-Or Expression`); + conditional-or operator '``||``' (see :ref:`Conditional-Or Expression`); - Conditional operator '?:' (see :ref:`Conditional Expressions`); - String concatenation operator '+' (see :ref:`String Concatenation`) that converts the boolean operand to a string (``true`` or ``false``), @@ -850,14 +857,16 @@ Character Types and Operations .. meta: frontend_status: Done -+-----------+--------------------------------------------------------------------+--------------------------+ -| Type | Type's Set of Values | Corresponding Class Type | -+===========+====================================================================+==========================+ -| ``char`` | Symbols with codes from \U+0000 to \U+FFFF inclusive, that is, | ``Char`` | -| | from 0 to 65,535 | | -+-----------+--------------------------------------------------------------------+--------------------------+ ++-----------+----------------------------------+--------------------------+ +| Type | Type's Set of Values | Corresponding Class Type | ++===========+==================================+==========================+ +| ``char`` | Symbols with codes from \U+0000 | ``Char`` | +| | to \U+FFFF inclusive, that is, | | +| | from 0 to 65,535 | | ++-----------+----------------------------------+--------------------------+ -|LANG| provides a number of operators to act on character values: +|LANG| provides a number of operators to act on character values as listed +below. - Comparison operators that produce a value of type *boolean*: @@ -874,13 +883,13 @@ Character Types and Operations and postfix (see :ref:`Postfix Decrement`); - Conditional operator '?:' (see :ref:`Conditional Expressions`); -- The string concatenation operator '+' (see :ref:`String Concatenation`), - which (if a string operand and character operand are available) converts - the character operand to a string and then creates a concatenation of the - two strings as a new string. +- The string concatenation operator '+' (see :ref:`String Concatenation`) that, + if a string operand and character operand are available, converts the + character operand to a string, and then creates a concatenation of the + two strings as a new ``string``. -The class ``Char`` also provides other constructors, methods and constants -which are part of the |LANG| standard library (see :ref:`Standard Library`). +The class ``Char`` also provides other constructors, methods, and constants +that are parts of the |LANG| standard library (see :ref:`Standard Library`). .. index:: char @@ -946,7 +955,7 @@ Objects .. meta: frontend_status: Done -An *object* can be a *class instance*, *function instance*, or an *array*. +An *object* can be a *class instance*, a *function instance*, or an *array*. The pointers to these objects are called *references* or reference values. @@ -998,12 +1007,14 @@ parameter are as follows: - Conditional operator '?:' (see :ref:`Conditional Expressions`). -Multiple references to an object are possible. Most objects have state. The -state is stored in the field if an object is an instance of class, or in a -variable that is an element of an array object. If two variables contain -references to the same object, and the state of that object is modified in -one variable’s reference, then the state so modified can be seen in the -other variable’s reference. +Multiple references to an object are possible. + +Most objects have state. The state is stored in the field if an object is +an instance of class, or in a variable that is an element of an array object. + +If two variables contain references to the same object, and the state of that +object is modified in one variable’s reference, then the state so modified can +be seen in the other variable’s reference. .. index:: operator @@ -1040,10 +1051,8 @@ other variable’s reference. frontend_status: Partly The class ``Object`` is a supertype of all other classes, interfaces, string, -arrays, unions, function types, and enum types. - -Thus all of them inherit (see :ref:`Inheritance`) the class ``Object``’s -methods as summarized below: +arrays, unions, function types, and enum types. Thus all of them inherit (see +:ref:`Inheritance`) the methods of the class ``Object`` as summarized below: - The method ``equals`` defines a notion of object equality, which is based on the comparison of values rather than references. @@ -1051,6 +1060,9 @@ methods as summarized below: - The method ``toString`` returns a string representation of the object. +Though the name ``object`` refers to type ``Object``, it is recommended to +use ``Object`` in all cases. + .. index:: class type function call expression @@ -1080,10 +1092,8 @@ methods as summarized below: .. meta: frontend_status: Done -The ``string`` type stores sequences of characters as Unicode UTF-16 code -units. - -*String* is the predefined type. +Type ``string`` is a predefined type. It stores sequences of characters as +Unicode UTF-16 code units. Type ``string`` includes all string literals, e.g., ``'abc'``. The value of a string object cannot be changed after it is created, i.e., a string @@ -1093,7 +1103,7 @@ If the result is not a constant expression (see :ref:`Constant Expressions`), then the string concatenation operator '+' (see :ref:`String Concatenation`) implicitly creates a new string object. -While the ``String`` type is the alias to ``string``, it is recommended to +Though the name ``String`` refers to the type ``string``, it is recommended to use ``string`` in all cases. .. index:: @@ -1119,7 +1129,7 @@ use ``string`` in all cases. The class ``never`` is a subclass (see :ref:`Subtyping`) of any other class. -The ``never`` class has no instances, and is used to represent values that +The ``never`` class has no instances; it is used to represent values that never exist (a function with this return type never returns but only throws an error or exception). @@ -1147,7 +1157,7 @@ an error or exception). ``void`` Type ============= -The ``void`` type has a single value, and is typically used as the return +The ``void`` type has a single value; it is typically used as the return type if: - A function returns no value of another type (similarly to type ``Unit`` @@ -1164,23 +1174,14 @@ type if: generic type type parameter argument - -The code below: - .. code-block:: typescript :linenos: - function foo () + function foo () // short form, which is equivalent to the following + function foo (): void // full form -is equivalent to the following: - -.. code-block:: typescript - :linenos: - - function foo (): void - - class A - let a = new A() + class A + let a = new A() // type parameter is irrelevant | @@ -1193,14 +1194,14 @@ Array Types frontend_status: Partly todo: Inherited methods from baseclass - Object can't be invoked now -*Array type* is the built-in type which is characterized by the following: +*Array type* is the built-in type characterized by the following: - Any object of array type contains elements indexed by integer position starting from 0; -- Access to any array element is performed at the same time; +- Access to any array element is performed within the same time; - While being passed to non-|LANG| environment, an array is represented as a contiguous memory location; -- Types of all arrays elements are upper-bounded by the element type +- Types of all array elements are upper-bounded by the element type specified in the array declaration. .. index:: @@ -1209,13 +1210,13 @@ Array Types access array -Two basic operations with array elements are taking elements out of and -putting elements into an array. Both operations use the ``[ ]`` operator -and index expression for that. -Another important operation implemented as the read-only field ``length`` -which allows to know the number of elements in the array. +Two basic operations with array elements take elements out of, and put +elements into an array by using the ``[ ]`` operator and index expression. + +Another important operation is the read-only field ``length``. It allows +knowing the number of elements in the array. -The syntax for built-in array type is below: +The example of syntax for thebuilt-in array type is below: .. index:: array element @@ -1228,10 +1229,11 @@ The syntax for built-in array type is below: type '[' ']' ; -A family of array types that are part of the standard library is described -in full in the library documentation. A common characteristic of such types -is that the ``[ ]`` operator can be applied to variables of all array types -and their derived ones as well. +The family of array types that are parts of the standard library (see +:ref:`Standard Library`), including all available operations, is described +in the library documentation. Common to these types is that the ``[ ]`` +operator can be applied to variables of all array types and to their derived +types. .. index:: array type @@ -1256,7 +1258,7 @@ A type alias can set a name for an array type (see :ref:`Type Alias Declaration` type Matrix = number[][] /* Two-dimensional array */ -As an object, an array is assignable to a variable of type Object: +As an object, an array is assignable to a variable of type *Object*: .. code-block:: typescript :linenos: @@ -1285,7 +1287,7 @@ Function Types A *function type* can be used to express the expected signature of a function. A function type consists of the following: -- List of parameters (can be empty); +- List of parameters (which can be empty); - Optional return type; - Optional keyword ``throws``. @@ -1368,7 +1370,7 @@ and conversions in :ref:`Function Types Conversions`. ``null`` Type ============= -The ``null`` type’s single value is represented by the keyword ``null`` +The only value of type ``null`` is represented by the keyword ``null`` (see :ref:`Null Literal`). Using type ``null`` as type annotation is not recommended, except in @@ -1388,11 +1390,11 @@ nullish types (see :ref:`Nullish Types`). ``undefined`` Type ================== -The ``undefined`` type’s single value is represented by the keyword +The only value of type ``undefined`` is represented by the keyword ``undefined`` (see :ref:`Undefined Literal`). Using type ``undefined`` as type annotation is not recommended, -except in nullish types, see :ref:`Nullish Types`. +except in nullish types (see :ref:`Nullish Types`). .. index:: type undefined @@ -1415,14 +1417,16 @@ Tuple Types ; A *tuple* type is a reference type created as a fixed set of other types. -Values of tuple types are groups of values of different types that comprise -the tuple type. Such types are specifed in the same order as those types -are declared within the tuple type declarartion. It implies that each tuple -element has its own type. +The value of a tuple type is a group of values of other types that comprise +the tuple type. Such other types are specifed in the same order as declared +within the tuple type declarartion. Each tuple element is thus implied to +have its own type. The operator ``[ ]`` (square brackets) is used to acess elements of a tuple -in a manner similar to that used to access elements of an array. The index -expression is of *integer* type, and the index of the 1st tuple element is *0*. -Only constant expressions can be used as index to get access top tuple elements. +in a manner similar to that used to access elements of an array. + +The index expression is of *integer* type, and the index of the 1st tuple +element is *0*. Only constant expressions can be used as index to get access +to tuple elements. .. code-block:: typescript :linenos: @@ -1434,37 +1438,14 @@ Only constant expressions can be used as index to get access top tuple elements. *Object* (see :ref:`Object Class Type`) is a super type for any tuple type. -.. - Tuple type is compatible with an array type (see :ref:`Array Types`) when - the type of array element is a super type for all tuple type elements' types. - And of course *Object* (see :ref:`Object Class Type`) is a super type for - any tuple type. - .. code-block:: typescript - :linenos: - let tuple: [number, number, string, boolean, Object] = - [ 6, 7, "abc", true, 666] - let array: Object[] = tuple /* Object is a super type for number, string, - boolean and Object */ - let object: Object = tuple // This works too - -An empty tuple is a corner case and is added to support compatibility with the -|TS|. +An empty tuple is a corner case. It is only added to support compatibility +with |TS|. .. code-block:: typescript :linenos: let empty: [] = [] // empty tuple with no elements in it -.. - Tuple type has the same set of operations like arrays. So, not only ``[ ]`` - (square brackets) but length is available for tuples as well as all other - operations. - .. code-block:: typescript - :linenos: - let empty: [] = [] - console.log ("# of tuple elements is ", empty.length) - - | .. _Union Types: @@ -1480,17 +1461,17 @@ Union Types A *union* type is a reference type created as a combination of other types or values. Values of union types can be valid values of all -types and values of literals the union was created from. +types and literals the union is created from. -A :index:`compile-time error` occurs if the type in the right-hand-side -of the union type declaration leads to a circular reference. +A :index:`compile-time error` occurs if the type in the right-hand side +of a union type declaration leads to a circular reference. -If a *union* uses one of primitive types (see Primitive types in +If a *union* uses a primitive type (see *Primitive types* in :ref:`Types by Category`), then automatic boxing occurs to keep the reference nature of the type. -The reduced form of union types allows defining a type which has only -one value as in the following example: +The reduced form of *union* types allows defining a type which has only +one value, as in the example below: .. index:: union type @@ -1509,7 +1490,7 @@ one value as in the following example: let t1: T = 3 // OK let t2: T = 2 // Compile-time error -Below is a typical example of unit types usage: +A typical example of *union* type usage is shown below: .. code-block:: typescript :linenos: @@ -1531,9 +1512,10 @@ Below is a typical example of unit types usage: animal = 42 // One may assign the variable of the union type with any valid value -Different mechanisms can be used to get values of particular types from a union. +Different mechanisms can be used to get values of particular types from a +*union*. For example: -For example: +| .. code-block:: typescript :linenos: @@ -1566,21 +1548,35 @@ Below is an example for primitive types: let i: number = p as number // Explicit conversion from Primitive to number } -For values: +--- and for values: .. code-block:: typescript :linenos: type BMW_ModelCode = 325 | 530 | 735 - let bmw: BMW_ModelCode = 325 - if (bmw == 325){ - bmw = 525 - } else if (bmw == 525){ - bmw = 735 + let car_code: BMW_ModelCode = 325 + if (car_code == 325){ + car_code = 530 + } else if (car_code == 530){ + car_code = 735 } else { // pension :-) } +Please note that it will be a compile-time error to compare a variable of the +union type with the value which does not belong to this union type values + +.. code-block:: typescript + :linenos: + + type BMW_ModelCode = 325 | 530 | 735 + let car_code: BMW_ModelCode = 325 + if (car_code == 666){ ... } + /* + compile-time error as 666 does not belong to + values of type BMW_ModelCode + */ + | .. _Union Types Normalization: @@ -1607,11 +1603,11 @@ another: #. Identical types within the union type are replaced for a single type. #. Identical literals within the union type are replaced for a single literal. -#. If at least one type in the union is *Object* then the whole union type is +#. If at least one type in the union is *Object*, then the entire union type is reduced to *Object* type. -#. Otherwise, if there is at least one numeric type among the numeric union - types or numeric literals, then all such types or literals are replaced - for type *number*. +#. If there is at least one numeric type among the numeric union types or + numeric literals, then all such types or literals are replaced for type + *number*. #. Unless any of the above is true: - If there are two types *T1* and *T2* within the union type, and *T1* is @@ -1634,7 +1630,7 @@ another: As a result of this process, the normalized union type remains. -The below examples highlight how this works: +This operation is highlighted by the examples below: .. code-block:: typescript :linenos: @@ -1682,25 +1678,25 @@ Nullish Types type '|' ( 'null' | 'undefined' ) ; -All predefined and user-defined type declarations create non-nullish -types that cannot have a ``null`` or ``undefined`` value at runtime. +All predefined and user-defined type declarations create non-nullish types. +Non-nullish types cannot have a ``null`` or ``undefined`` value at runtime. *T* \| ``null`` or *T* \| ``undefined`` can be used as the type to specify a nullish version of type *T*. -A variable declared to have the type *T* \| ``null`` can hold values of +A variable declared to have the type *T* \| ``null`` can hold values of the type *T* and its derived types, or the value ``null``. Such type is called a *nullable type*. A variable declared to have the type *T* \| ``undefined`` can hold values -of type *T* and its derived types, or the value ``undefined``. +of the type *T* and its derived types, or the value ``undefined``. A :index:`compile-time error` occurs if *T* is not a reference type. -A reference which is ``null`` or ``undefined`` is called *nullish* value. +A reference which is ``null`` or ``undefined`` is called a *nullish* value. -An operation that is safe with no regard to the presence or absence of +An operation that is safe with no regard to the presence or absence of nullish values (e.g., re-assigning one nullable value to another) can -be used as is for nullish types. +be used 'as is' for nullish types. The following nullish-safe options exist for operations on nullish type *T* that can potentially violate null safety (e.g., access to a property): @@ -1727,15 +1723,17 @@ that can potentially violate null safety (e.g., access to a property): - Using safe operations: - - Safe method call (for details see :ref:`Method Call Expression`); - - Safe field access expression (for details see :ref:`Field Access Expressions`); - - Safe indexing expression (for details see :ref:``Indexing Expression``); - - Safe function call (for details see :ref:`Function Call Expression`); + - Safe method call (see :ref:`Method Call Expression` for details); + - Safe field access expression (see :ref:`Field Access Expressions` + for details); + - Safe indexing expression (see :ref:``Indexing Expression`` for details); + - Safe function call (see :ref:`Function Call Expression` for details); - Downcasting from *T* \| ``null`` or *T* \| ``undefined`` to *T*: - - Cast expression (for details see :ref:`Cast Expressions`); - - Ensure-not-nullish expression (for details see :ref:`Ensure-Not-Nullish Expressions`); + - Cast expression (see :ref:`Cast Expressions` for details); + - Ensure-not-nullish expression (see :ref:`Ensure-Not-Nullish Expressions` + for details); - Supplying a default value to use if a nullish value is present: @@ -1765,7 +1763,7 @@ DynamicObject Type todo: now it supports only JSValue, need to add full abstract support The interface *DynamicObject* is used to provide seamless interoperability -with dynamic languages as Javascript and TypeScript, and +with dynamic languages (e.g., Javascript and TypeScript), and to support advanced language features such as *dynamic import* (see :ref:`Dynamic Import`). This interface is defined in the standard library (see :ref:`Standard Library`). @@ -1774,7 +1772,7 @@ It is a common interface for a set of wrappers (also defined in the standard library) that provide access to underlying objects. The *DynamicObject* instance cannot be created directly; only an instance of a specific wrapper object can be instantiated. -For example, the result of the *dynamic import* expression (see +For example, a result of the *dynamic import* expression (see :ref:`Dynamic Import Expression`) is an instance of the dynamic object implementation class that wraps an object containing exported entities of the imported module. @@ -1818,7 +1816,7 @@ DynamicObject Field Access todo: now it supports only JSValue, need to add full abstract support The field access expression *D.F*, where *D* is of type *DynamicObject*, -is treated as an access to a property of the underlying object. +is handled as an access to a property of an underlying object. If the value of a field access is used, then it is wrapped in the instance of *DynamicObject*, since the actual type of the field is not known at compile @@ -1864,7 +1862,7 @@ DynamicObject Method Call todo: now it supports only JSValue, need to add full abstract support The method call expression *D.F()*, where *D* is of type *DynamicObject*, -is treated as a call of the instance method of the underlying object. +is handled as a call of the instance method of an underlying object. If the result of a method call is used, then it is wrapped in the instance of *DynamicObject*, since the actual type of the returned value is not known @@ -1882,7 +1880,7 @@ The wrapper must raise an error if: - No method with the specified name exists in the underlying object; or - The signature of the method is not compatible with the types of the - call's arguments. + call arguments. .. index:: DynamicObject @@ -1907,7 +1905,7 @@ DynamicObject Indexing Access todo: now it supports only JSValue, need to add full abstract support The indexing access expression *D[index]*, where *D* is of type *DynamicObject*, -is treated as an indexing access to the underlying object. +is handled as an indexing access to an underlying object. .. code-block:: typescript :linenos: @@ -1936,24 +1934,24 @@ Default Values for Types .. meta: frontend_status: Partly -**Note**: this is part of the experimental mode of the |LANG|. +**Note**: This is part of the |LANG|'s experimental mode. Some types use so-called *default values* for variables without explicit initialization (see :ref:`Variable Declarations`), including the following: - All primitive types (see the table below). -- All union types which have one nullish (see :ref:`Nullish Types`) value use - appropriate nullish value as default (see the table below). +- All union types that have one nullish (see :ref:`Nullish Types`) value, + and use an appropriate nullish value as default (see the table below). .. - Nullable reference types with the default value ``null`` (see :ref:`Literals`). All other types, including reference types and enumeration types, have no default values. -A variable of such types must be initialized explicitly with a value +A variables of such a type must be initialized explicitly with a value before its first use. -The primitive types’ default values are as follows: +The default values of primitive types are as follows: .. index:: default value @@ -1986,7 +1984,7 @@ The primitive types’ default values are as follows: | ``boolean`` | ``false`` | +----------------+--------------------+ -The nullish union types’ default values are as follows: +The default values of nullish union types are as follows: +----------------+--------------------+ | Data Type | Default Value | @@ -2006,7 +2004,7 @@ The nullish union types’ default values are as follows: f2: string|undefined f3?: boolean } - let a = new A + let a = new A() console.log (a.f1, a.f2, a.f3) // Output: null, undefined, undefined diff --git a/plugins/ets/doc/spec/4_names.rst b/plugins/ets/doc/spec/4_names.rst index c4fc23a1e..1939fe012 100644 --- a/plugins/ets/doc/spec/4_names.rst +++ b/plugins/ets/doc/spec/4_names.rst @@ -23,13 +23,13 @@ declarations, and scopes. Each entity in a |LANG| program---a variable, a constant, a class, a type, a function, a method, etc.---is introduced via a *declaration*. -An entity declaration assigns a *name* to the entity declared. -Further in the program text, the name is used to refer to the entity. +An entity declaration assigns a *name* to the entity declared. The name +is used to refer to the entity further in the program text. -Each declaration is valid (i.e., available and known) only within its -*scope*. Informally, scope is the region of the program text where the -entity is declared, and where it can be referred to by its simple -(unqualified) name. See :ref:`Scopes` for more details. +Each declaration is valid (i.e., available and known) only within its *scope*. +Scope is the region of the program text where the entity is declared and can +be referred to by its simple (unqualified) name (see :ref:`Scopes` for more +details). .. index:: variable @@ -57,12 +57,12 @@ Names A name refers to any declared entity. -*Simple* names consist of a single identifier; *qualified* names consist +*Simple names* consist of a single identifier; *qualified names* consist of a sequence of identifiers with the '.' tokens as separators. A qualified name *N.x* (where *N* is a simple or qualified name, and ``x`` is an identifier) can refer to a *member* of a package, or a reference type -(see :ref:`Reference Types`). *N* can name: +(see :ref:`Reference Types`). *N* can name the following: - A package, of which ``x`` is a member. @@ -101,9 +101,8 @@ Declarations .. meta: frontend_status: Done -Declarations introduce named entities in appropriate **declaration scope** -(see :ref:`Scopes`). Any declaration in its declaration scope must be -*distinguishable*. +A declaration introduces a named entity in an appropriate **declaration scope** +(see :ref:`Scopes`). .. index:: named entity @@ -123,14 +122,14 @@ Distinguishable Declarations todo: const PI:()=>int = ():int=>{return 5};function PI():float{return 3.14};let a = PI(); error: a is 5 todo: need scpec clarification -Declarations must be distinguishable in a declaration scope. A -:index:`compile-time error` occurs otherwise. +Each declaration in the declaration scope must be *distinguishable*. +A :index:`compile-time error` occurs otherwise. -Declarations are distinguishable if they: +Declarations are *distinguishable* if: -- Have different names; +- They have different names; -- Are distinguishable by signatures (see +- They are distinguishable by signatures (see :ref:`Declaration Distinguishable by Signatures`). .. index:: @@ -139,7 +138,7 @@ Declarations are distinguishable if they: name signature -Example of declarations distinguishable by names: +The examples below are declarations distinguishable by names: .. code-block:: typescript :linenos: @@ -149,8 +148,8 @@ Example of declarations distinguishable by names: function Pi() {} type IP = number[] -Example of declarations that are indistinguishable by names, and cause a -:index:`compile-time error`: +The examples below are declarations indistinguishable by names. +Such declarations cause compile-time errors: .. code-block:: typescript :linenos: @@ -173,6 +172,7 @@ Example of declarations that are indistinguishable by names, and cause a .. index:: distinguishable declaration + compile-time error | @@ -190,8 +190,8 @@ In other words, the name is accessible in some context if it can be used in this context by its *simple* name. The nature of usage of a scope depends on the kind of the name. -A type name can be used to declare variables or constants; a name of a function -can be used to call that function. +A type name is used to declare variables or constants; +a function name is used to call that function. .. index:: scope @@ -264,7 +264,7 @@ The scope of a name depends on the context the name is declared in: .. _enum-access: - *Enum level scope*: as every enumeration defines a type inside a package or - module then its scope is identical to the package or module level scope. + module, then its scope is identical to the package or module level scope. All enumeration constants have the same scope as the enumeration itself. .. index:: @@ -301,7 +301,7 @@ The scope of a name depends on the context the name is declared in: - The scope of a name declared immediately inside the body of a function (method) declaration is the body of that function declaration (*method* - or *function scope*) from the place of declaration, and up to the end of + or *function scope*) from the place of declaration and up to the end of the body. .. index:: @@ -314,7 +314,7 @@ The scope of a name depends on the context the name is declared in: .. _block-access: - The scope of a name declared inside a statement block is the body of - such statement block from the point of declaration, and down to the end + the statement block from the point of declaration and down to the end of the block (*block scope*). .. index:: @@ -331,12 +331,16 @@ The scope of a name depends on the context the name is declared in: let y = 1 } -Scopes of two names can overlap (e.g., when statements are nested); in -that case the name with the innermost declaration takes precedence, and -access to the outer name is not accessible. +Scopes of two names can overlap (e.g., when statements are nested). If scopes +of two names overlap, then: + +- The innermost declaration takes precedence; and +- Access to the outer name is impossible. + + +Class, interface, and enum members can only be accessed by applying the dot +operator '.' to an instance; accessing them otherwise is impossible. -Class, interface and enum members are not directly accessible in a scope; -in order to access them, the dot operator '.' must be applied to an instance. .. index:: name @@ -392,9 +396,10 @@ Type Alias Declaration todo: type alias can be as local declaration now, but the spec says it can be only topDeclaration todo: type alias name shouldn't be handled as variable name (eg: type foo = Double; let foo : int = 0 --> now error) -Type aliases enable using meaningful and concise notations by providing: +Type aliases enable using meaningful and concise notations by providing the +following: -- Names for anonymous types (array, function, union types); or +- Names for anonymous types (array, function, and union types); or - Alternative names for existing types. @@ -429,8 +434,8 @@ Meaningful names can be provided for anonymous types as follows: type Predicate = (x: T) => Boolean type NullableNumber = Number | null -If the existing type name is too long, then it is reasonable to introduce -a shorter new name by using type alias, particularly for a generic type. +If the existing type name is too long, then a shorter new name can be +introduced by using type alias (particularly for a generic type). .. code-block:: typescript :linenos: @@ -438,8 +443,8 @@ a shorter new name by using type alias, particularly for a generic type. type Dictionary = Map type MapOfString = Map -A type alias introduces no new type but acts only as a new name, while its -meaning remains the same as the original type’s. +A type alias acts only as a new name. It neither changes the meaning of the +original type nor introduces a new type. .. code-block:: typescript :linenos: @@ -473,11 +478,11 @@ type alias declaration, see :ref:`Recursive Type Aliases`. Recursive Type Aliases ====================== -For a type alias defined as *type A = something*, *A* can be used recursively -if it is used as one of the following: +In a type alias defined as *type A = something*, *A* can be used recursively +if it is one of the following: - Array element type: *type A = A[]*; or -- Type argument of some generic type: type A = C. +- Type argument of a generic type: type A = C. .. code-block:: typescript :linenos: @@ -490,7 +495,7 @@ if it is used as one of the following: type D = string | Array // ok -Any other usage causes a compile-time error, as the compiler +Any other use causes a compile-time error, because the compiler does not have enough information about the defined alias: .. code-block:: typescript @@ -500,8 +505,8 @@ does not have enough information about the defined alias: type F = string | E // compile-time error -Exactly the same rules apply to a generic type alias defined as -*type A = something*. +The same rules apply to a generic type alias defined as +*type A = something*: .. code-block:: typescript :linenos: @@ -520,8 +525,8 @@ a type argument: type A = Array // compile-time error -**Note**: there is no restriction on using a type parameter *G* in -the right side of a type alias declaration, and the following code +**Note**: There is no restriction on using a type parameter *G* in +the right side of a type alias declaration. The following code is valid: .. code-block:: typescript @@ -530,6 +535,7 @@ is valid: type NodeValue = G | Array | Array>; | +| .. _Variable and Constant Declarations: @@ -552,8 +558,8 @@ Variable Declarations todo: es2panda bug: A local variable must be explicitly given a value before ifis used, by either todo: "Every variable in program must have a value before its value is used" - Can't be guaranteed in compile time that a non-nullable array component is initialized. initialization or assignment. But we got no error if don't init a primitive typed local var. -A *variable declaration* introduces a new named variable, which can be assigned -with an initial value. +A *variable declaration* introduces a new named variable that can be assigned +an initial value. .. code-block:: abnf @@ -574,13 +580,14 @@ with an initial value. '=' expression ; -The type *T* of a variable introduced by a variable declaration is determined -as follows: +When a variable is introduced by a variable declaration, type *T* of the +variable is determined as follows: - *T* is the type specified in a type annotation (if any) of the declaration. - If *'?'* is used after the name of the variable, then the variable's type is - *type | undefined.* If the declaration also has an initializer, then the - initializer expression must be compatible with *T* (see :ref:`Type Compatibility with Initializer`). + If *'?'* is used after the name of the variable, then the type of the + variable is *type | undefined.* If the declaration also has an initializer, + then the initializer expression must be compatible with *T* (see + :ref:`Type Compatibility with Initializer`). - If no type annotation is available, then *T* is inferred from the initializer expression (see :ref:`Type Inference from Initializer`). @@ -606,16 +613,15 @@ as follows: let f = (p: number) => b + p let x // compile-time error -- either type or initializer -Every variable in a program must have an initial value before its value is used. - -There are several ways to identify such initial value: +Every variable in a program must have an initial value before it can be used. +The initial value can be identified as follows: -- An initial value is explicitly specified by using an *initializer*. +- The initial value is explicitly specified by an *initializer*. - Each method or function parameter is initialized to the corresponding - argument value provided by the caller of that method or function. + argument value provided by the caller of the method or function. - Each constructor parameter is initialized to the corresponding - argument value provided by: - + argument value as provided by: + + Class instance creation expression (see :ref:`New Expressions`), or + Explicit constructor call (see :ref:`Explicit Constructor Call`). @@ -624,7 +630,7 @@ There are several ways to identify such initial value: - Each class, instance, local variable, or array element is initialized with a *default value* (see :ref:`Default Values for Types`) when it is created. -Otherwise, a variable is not initialized, and a :index:`compile-time error` +Otherwise, the variable is not initialized, and a :index:`compile-time error` occurs. If an initializer expression is provided, then additional restrictions apply @@ -667,7 +673,7 @@ Constant Declarations A *constant declaration* introduces a named variable with a mandatory explicit value. -The value of a constant cannot be changed by using an assignment expression +The value of a constant cannot be changed by an assignment expression (see :ref:`Assignment`). However, if the constant is an object or array, then its properties or items can be modified. @@ -689,11 +695,11 @@ The type *T* of a constant declaration is determined as follows: - If *T* is the type specified in a type annotation (if any) of the declaration, then the initializer expression must be compatible with - that *T* (see :ref:`Type Compatibility with Initializer`). + *T* (see :ref:`Type Compatibility with Initializer`). - If no type annotation is available, then *T* is inferred from the initializer expression (see :ref:`Type Inference from Initializer`). -- If *'?'* is used after the name of the constant, then the type of the - constant is *T | undefined*, regardless of whether *T* is identified +- If '*?*' is used after the name of the constant, then the type of the + constant is ``T | undefined``, regardless of whether *T* is identified explicitly or via type inference. .. index:: @@ -733,28 +739,28 @@ Type Compatibility with Initializer frontend_status: Done If a variable or constant declaration contains the type annotation *T* and the -initializer expression *E*, then the type of *E* must be equal to that of *T*; -otherwise, one of the following assertions must be true: - -+-----------------------+----------------------------------+-------------------------------------+ -| **T is** | **E is** | **Assertion** | -+=======================+==================================+=====================================+ -| One of integer types | integer literal or compile-time | Value of *E* is in bound of | -| | constant expression of some | type *T* | -| | integer type | | -+-----------------------+----------------------------------+-------------------------------------+ -| Type *char* | integer literal | Value of *E* is in bounds of type | -| | | *T* | -+-----------------------+----------------------------------+-------------------------------------+ -| Float type (*float* | floating-point literal or | Value of *E* is in bounds of type | -| or *double*) | compile-time constant expression | *T*. *This conversion can lead to | -| | of a float type | the loss of precision, see | -| | | “Narrowing Primitive Conversion”.* | -+-----------------------+----------------------------------+-------------------------------------+ -| Class type | of a class type | Type of *E* is derived class of *T* | -+-----------------------+----------------------------------+-------------------------------------+ - -Unless at least one of these conditions is fulfilled, then an error is thrown. +initializer expression *E*, then the type of *E* must be equal to that of *T*. +Otherwise, one of the following assertions must be true: + ++-----------------------+----------------------------------+---------------------------------------+ +| **T is** | **E is** | **Assertion** | ++=======================+==================================+=======================================+ +| One of integer types | integer literal or compile-time | Value of *E* is in bound of | +| | constant expression of some | type *T* | +| | integer type | | ++-----------------------+----------------------------------+---------------------------------------+ +| Type *char* | integer literal | Value of *E* is in bounds of type | +| | | *T* | ++-----------------------+----------------------------------+---------------------------------------+ +| Float type (*float* | floating-point literal or | Value of *E* is in bounds of type | +| or *double*) | compile-time constant expression | *T*. *This conversion can lead to | +| | of a float type | the loss of precision (see | +| | | “Narrowing Primitive Conversion”).* | ++-----------------------+----------------------------------+---------------------------------------+ +| Class type | of a class type | Type of *E* is a derived class of *T* | ++-----------------------+----------------------------------+---------------------------------------+ + +An error is thrown if at least one of these conditions is not fulfilled. .. index:: compile-time error @@ -785,13 +791,12 @@ Type Inference from Initializer frontend_status: Partly todo: spec issue: "If initializer expression is a null literal('null') the compiler error should be reported". Why is it striked out? "let a = null" should be CTE A: scpec will be changed, a will have "Object|null tyoe" -The type of a declared entity is: +The type of a declared entity is one of the following: - The type of the initializer expression if a variable or constant - declaration contains no explicit type annotation; or + declaration contains no explicit type annotation. -- *Object \| null* if the initializer expression is a null literal - (*null*). +- *Object \| null* if the initializer expression is the *null* literal. .. index:: type @@ -835,13 +840,13 @@ Function *overload signature* allows calling a function in different ways (see In a **native function** (see :ref:`Native Functions`), the body is omitted. -If a function is declared as **generic** (see :ref:`Generics`), then type -parameters must be specified. +If a function is declared as **generic** (see :ref:`Generics`), then its type +parameters must be specified. -Native functions are described in the experimental section (see +Native functions are described in the chapter Experimental Features (see :ref:`Native Functions`). -Functions must be declared on the top-level (see :ref:`Top-Level Statements`). +Functions must be declared on the top level (see :ref:`Top-Level Statements`). Function expressions must be used to define lambdas (see :ref:`Lambda Expressions`). @@ -919,9 +924,9 @@ Parameter List .. meta: frontend_status: Done -A signature contains a *parameter list* that specifies an identifier as -each parameter name and a type of each parameter. Every parameter’s type must -be explicitly defined. +A signature contains a *parameter list* that specifies an identifier of +each parameter name, and the type of each parameter. The type of each +parameter must be explicitly defined. .. code-block:: abnf @@ -997,9 +1002,9 @@ There are two forms of *optional parameters*: The first form contains an expression that specifies a *default value*. That -is called a *parameter with default value*. If the argument -corresponding to that parameter is omitted in a function call, then the value -of the parameter is set to the *default value*. +is called a *parameter with default value*. The value of the parameter is set +to the *default value* if the argument corresponding to that parameter is +omitted in a function call. .. index:: optional parameter @@ -1021,11 +1026,11 @@ of the parameter is set to the *default value*. pair(1) // prints: 1 7 The second form is a short notation for a parameter of a union type -*T* | ``undefined`` with the default value ``undefined``. -It means that *identifier '?' ':' type* is equivalent to +``T | undefined`` with the default value ``undefined``. It means that +*identifier '?' ':' type* is equivalent to *identifier ':' type | undefined = undefined*. If a type is of the value type kind, then (similar to :ref:`Union Types`) -implicit boxing must be applied in the following manner: +implicit boxing must be applied as follows: *identifier '?' ':' valueType* is equivalent to *identifier ':' referenceTypeForValueType | undefined = undefined*. @@ -1043,6 +1048,10 @@ implicit boxing must be applied in the following manner: For example, the following two functions can be used in the same way: +| +| +| + .. code-block:: typescript :linenos: @@ -1075,7 +1084,7 @@ Rest Parameter A *rest parameter* allows functions or methods to take unbounded numbers of arguments. -*Rest parameters* have the '``...``' symbol mark before a parameter name. +*Rest parameters* have the '``...``' symbol mark before the parameter name. .. code-block:: typescript :linenos: @@ -1123,6 +1132,8 @@ number of arguments of type ``T``. If an argument of type ``T[]`` is prefixed with the *spread* operator '``...``', then only one argument can be accepted. +| + .. code-block:: typescript :linenos: @@ -1193,7 +1204,7 @@ Return Type .. meta: frontend_status: Done -An omitted function, or method return type can be inferred from the function, +An omitted function or method return type can be inferred from the function, or the method body. A :index:`compile-time error` occurs if a return type is omitted in a native function (see :ref:`Native Functions`). @@ -1203,21 +1214,21 @@ the following conditions: - If there is no return statement, or if all return statements have no expressions, then the return type is *void* (see :ref:`void Type`). - If there is at least one return statement with an expression, and the - type of each expression of each return statement is *R*, then the + type of each expression in each return statement is *R*, then the return type is *R*. -- If there are *k* return statements (assuming that *k* is two, or more) - with expressions of types (*T*:sub:`1`, ``...``, *T*:sub:`k`), and *R* +- If there are *k* return statements (where *k* is two or more) with + expressions of types (*T*:sub:`1`, ``...``, *T*:sub:`k`), and *R* is the *least upper bound* (see :ref:`Least Upper Bound`) of these types, then the return type is *R*. - If the function is *async*, the return type is inferred by using the rules above, and the type *T* is not *Promise* type, then the return type is *Promise*. -Future compiler implementation can infer return type in more cases. If +Future compiler implementation are to infer return type in more cases. If the particular type inference case is not recognized by the compiler, then a corresponding :index:`compile-time error` occurs. -See the example below for an illustration of type inference: +The example below is an illustration of type inference: .. index:: return type @@ -1246,9 +1257,9 @@ See the example below for an illustration of type inference: function bar (condition: boolean) { if (condition) - return new Derived1 + return new Derived1() else - return new Derived2 + return new Derived2() } /* Return type of bar will be inferred as Base which is LUB for Derived1 and Derived2 */ @@ -1264,10 +1275,10 @@ Function Overload Signatures frontend_status: None The |LANG| language allows specifying a function that can be called in -different ways by writing *overload signatures*, i.e., by writing several -function headers which have the same name and different signatures, and are -followed by one implementation function. See also -:ref:`Methods Overload Signatures` for *method overload signatures*. +different ways by writing *overload signatures*. It means writing several +function headers that have the same name but different signatures, and are +followed by one implementation function (see :ref:`Methods Overload Signatures` +for *method overload signatures*). .. code-block:: abnf @@ -1283,7 +1294,7 @@ A call of a function with overload signatures is always a call of the implementation function. The example below has two overload signatures defined (one is parameterless, -and the other has one parameter): +and the other has a single parameter): .. index:: function overload signature @@ -1295,6 +1306,8 @@ and the other has one parameter): implementation method overload signature +| + .. code-block:: typescript :linenos: @@ -1308,16 +1321,16 @@ and the other has one parameter): foo("aa") // ok, 2nd signature is used The call of ``foo()`` is executed as a call of the implementation function -with the ``null`` argument, while the call of ``foo(x)`` is executed as a call +with the ``null`` argument; the call of ``foo(x)`` is executed as a call of the implementation function with the ``x`` argument. A :index:`compile-time error` occurs if the signature of function implementation is not *overload signature-compatible* with each overload signature. It means that a call of each overload signature must be replaceable -for the correct call of the implementation function. This can be achieved by +for the correct call of the implementation function. That can be achieved by using optional parameters (see :ref:`Optional Parameters`), or *least upper -bound* types (see :ref:`Least Upper Bound`). See -:ref:`Overload Signature Compatibility` for the exact semantic rules. +bound* types (see :ref:`Least Upper Bound`). The exact semantic rules can +be found in :ref:`Overload Signature Compatibility`. A :index:`compile-time error` occurs unless all overload signatures are exported or non-exported. diff --git a/plugins/ets/doc/spec/5_generics.rst b/plugins/ets/doc/spec/5_generics.rst index 49482b865..6e2b93765 100644 --- a/plugins/ets/doc/spec/5_generics.rst +++ b/plugins/ets/doc/spec/5_generics.rst @@ -18,7 +18,7 @@ Generics .. meta: frontend_status: Partly -Class, interface, method, constructor and function are program entities +Class, interface, method, constructor, and function are program entities that can be generalized in the |LANG| language. Generalization is parametrizing an entity by one or several types. A generalized entity is introduced by a *generic declaration* (also called *generic* @@ -31,6 +31,8 @@ for brevity). generic declaration generic +| + .. _Generic Declarations: Generic Declarations @@ -64,15 +66,15 @@ specified in the instantiation are called *type arguments*. construct type argument -In an *implicit* instantiation, type arguments are not specified explicitly, -but are inferred from the context the generic is referred in. +In an *implicit* instantiation, type arguments are not specified explicitly. +They are inferred from the context the generic is referred in. Implicit instantiation is possible only for functions and methods. The result of instantiation is a *real*, non-parametrized program entity: class, interface, method, constructor, or function. Such entity is treated exactly as an ordinary class, interface, method, constructor, or function. -Conceptually, a generic class, an interface, a method, a constructor or a +Conceptually, a generic class, an interface, a method, a constructor, or a function defines a set of classes, interfaces, methods, constructors, or functions respectively (see :ref:`Generic Instantiations`). @@ -88,6 +90,8 @@ functions respectively (see :ref:`Generic Instantiations`). constructor function +| + .. _Generic Parameters: Generic Parameters @@ -101,7 +105,7 @@ type parameter to be *generic*. The type parameter is declared in the type parameter section, and can be used as an ordinary type inside a generic. Syntactically, the type parameter is an unqualified identifier. -For the scope of type parameters see :ref:`Scopes`. +See :ref:`Scopes` for the scope of type parameters. Each type parameter has a *constraint* (see :ref:`Type Parameter Constraint`). @@ -121,6 +125,8 @@ Type parameters can also have default types (see :ref:`Type Parameter Default`). default type type parameter +| + .. code-block:: abnf typeParameters: @@ -237,8 +243,6 @@ section depends on itself. constraint compile-time error -| - .. code-block:: typescript :linenos: @@ -263,7 +267,7 @@ Generic Instantiations frontend_status: Partly As mentioned before, a generic class, interface, or function declaration -defines a set of corresponding non-generic entities. A generic entity +defines a set of corresponding non-generic entities. A generic entity must be *instantiated* in order to get a non-generic entity out of it. The instantiation is specified by providing a list of *type arguments* that substitute corresponding type parameters of the generic: @@ -279,7 +283,7 @@ that substitute corresponding type parameters of the generic: *G* < *T*:sub:`1`, ``...``, *T*:sub:`n`> -where <*T*:sub:`1`, ``...``, *T*:sub:`n`> is the list of type arguments +---where <*T*:sub:`1`, ``...``, *T*:sub:`n`> is the list of type arguments for the generic declaration *G*. If *C*:sub:`1`, ``...``, *C*:sub:`n` is the constraint for the corresponding @@ -349,7 +353,7 @@ However, a compile-time error occurs if a type parameter without a default value follows a type parameter with a default value in the declaration of a generic type. -The examples below illustrate this for both classes and functions. +The examples below illustrate this for both classes and functions: .. index:: type parameter @@ -387,7 +391,6 @@ The examples below illustrate this for both classes and functions. let c2 = new C2 // equal to C2 let c3 = new C2 // all 3 type arguments provided - | .. _Type Arguments: @@ -399,17 +402,14 @@ Type arguments can be reference types or wildcards. If a value type is specified as a type argument in the generic instantiation, then the boxing conversion applies to that type (see -:ref:`Predefined Numeric Types Conversions`). +:ref:`Primitive Types Conversions`). .. code-block:: abnf typeArguments: - '<' typeArgumentList? '>' + '<' typeArgumentList '>' ; -A *typeArgument* denotes a raw type (see :ref:`Raw Types`) unless a -*typeArgumentList* is provided. - A compile-time error occurs if type arguments are omitted in a parametrized function. @@ -424,6 +424,8 @@ function. parameterized function compile-time error +| + .. code-block:: abnf typeArgumentList: @@ -489,8 +491,8 @@ equivalent. A compile-time error occurs if: -- A wildcard is used in a parameterization of a function; -- A covariant wildcard is specified for a contravariant type parameter; +- A wildcard is used in a parameterization of a function; or +- A covariant wildcard is specified for a contravariant type parameter; or - A contravariant wildcard is specified for a covariant type parameter. .. index:: @@ -507,10 +509,10 @@ The rules below apply to the subtyping (see :ref:`Subtyping`) of two non-equivalent types *A* <: *B*, and an invariant type parameter *F* in case of use-site variance: -- *T* <: *T* -- *T* :> *T* -- *T* <*A*> <: *T* -- *T* <*A*> <: *T* +- *T* <: *T* ; +- *T* :> *T* ; +- *T* <*A*> <: *T* ; +- *T* <*A*> <: *T* . .. index:: subtyping @@ -521,7 +523,7 @@ Any two type arguments are considered *provably distinct* if: - The two arguments are not of the same type, and neither is a type parameter nor a wildcard; or -- One type argument is a type parameter, or a wildcard with an upper bound +- One type argument is a type parameter or a wildcard with an upper bound of *S*, the other *T* is not a type parameter and not a wildcard, and neither is a subtype of another (see :ref:`Subtyping`); or - Each type argument is a type parameter, or wildcard with upper bounds @@ -537,126 +539,6 @@ Any two type arguments are considered *provably distinct* if: | -.. _Raw Types: - -Raw Types -********* - -.. code-block:: abnf - - rawType: - identifier '<' '>' - ; - -**Note**: Raw types are added below to simplify the migration from other -languages that support this notion. Future versions of the language are -to disallow the use of raw types. - -A raw type is one of the following: - -- The reference type formed by taking a generic type declaration’s name - without the accompanying type argument list. -- An array type with a raw type element. -- A non-*static* member type of a raw type *R* not inherited from an - *R*’s superclass or superinterface. - -.. index:: - raw type - migration - reference type - generic type declaration - type argument - array type - raw type - non-static member type - inheritance - superclass - superinterface - member type - -Only a generic class, or interface type can be a raw type. - -Raw type superclasses and superinterfaces are the raw versions of respective -superclasses and superinterfaces of any generic type instantiations. - -The type of a constructor (see :ref:`Constructor Declaration`), instance method -(see :ref:`Instance Methods` for classes, :ref:`Interface Method Declarations` -and `Default Method Declarations` for interfaces), and non-*static* field (see -:ref:`Field Declarations`) of a raw type *C*, which is not inherited from -respective superclasses or superinterfaces, is the raw version of its type -in the generic declaration corresponding to *C*. - -The type of a *static* method or *static* field of a raw type *C*, and the type -of a method or field in the generic declaration corresponding to *C* are the -same. - -.. index:: - generic class - interface type - raw type - raw type superclass - raw type superinterface - instantiation - superclass - superinterface - generic type - constructor - instance method - interface method declaration - default method declaration - interface - non-static field - field declaration - inheritance - static method - static field - generic declaration - -A compile-time error occurs if: - -- Type arguments are passed to a non-*static* type member of a raw type - that is not inherited from its superclasses or superinterfaces. -- An attempt is made to use a type member of a parameterized type as a - raw type. - -.. index:: - compile-time error - type argument - non-static type member - raw type - inheritance - superclass - superinterface - type member - parameterized type - -A class’ supertype can be a raw type. - -Member access to a class is treated as normal, while member access to a -supertype is treated as that to a raw type. Calls to ``super`` are treated -as method calls to raw types in the class constructor. - -The use of raw types is a concession for the sake of compatibility with -legacy code, and is to be disallowed in future versions of the language. - -The use of a raw type always results in compile-time diagnostics in order -to ensure that potential typing rules violations are flagged. - -.. index:: - supertype - raw type - member access - class - member access - supertype - call - method call - class constructor - compatibility - - -| - .. _Utility Types: Utility Types @@ -721,10 +603,10 @@ The type *Record* constructs a container that maps keys (of type *K*) to values (of type *V*). The type *K* is restricted to ``number`` types, ``string`` types, union types -constructed from these types, and also literals of such types. +constructed from these types, and also literals of these types. A compile-time error occurs if any other type, or literal of any other type -is used as this type. +is used in place of this type. There are no restrictions on the type *V*. @@ -751,10 +633,10 @@ There are no restrictions on the type *V*. A special form of object literals is supported for instances of *Record* types (see :ref:`Object Literal of Record Type`). -Accessing to ``Record<``*K*``, ``*V*``>`` values is done by the *indexing +Access to ``Record<``*K*``, ``*V*``>`` values is done by the *indexing expression* like *r[index]*, where *r* is an instance of the type ``Record``, and *index* is the expression of the type *K*. The result of an indexing -expression is of the type *V*. +expression is of type *V*. .. index:: object literal diff --git a/plugins/ets/doc/spec/6_conversions.rst b/plugins/ets/doc/spec/6_conversions.rst index 4d65417f0..ea4204e8a 100644 --- a/plugins/ets/doc/spec/6_conversions.rst +++ b/plugins/ets/doc/spec/6_conversions.rst @@ -19,12 +19,11 @@ Contexts and Conversions frontend_status: Done Every expression written in the |LANG| programming language has a type that -is inferred at compile time. The *target type* of an expression is the type -*compatible* with the types expected in most contexts that expression -appears in. +is inferred at compile time. The *target type* of an expression must be +*compatible* with the types expected in most contexts the expression appears in. -There are two ways to improve convenience by facilitating the expression's -compatibility with its surrounding context: +There are two ways to improve convenience by facilitating the compatibility +of an expression with its surrounding context: #. The type of some non-standalone expressions can be inferred from the target type (the expression types can be different in different @@ -191,11 +190,10 @@ Type *T1* is compatible with type *T2* if one of the following conversions can be successfully applied to type *T1* to receive type *T2* as a result: - Identity conversion (see :ref:`Kinds of Conversion`); -- Predefined numeric types conversions (see :ref:`Predefined Numeric Types Conversions`); +- Primitive types conversions (see :ref:`Primitive Types Conversions`); - Reference types conversions (see :ref:`Reference Types Conversions`); - Function types conversions (see :ref:`Function Types Conversions`); - Enumeration types conversions -- experimental feature (see :ref:`Enumeration Types Conversions`); -- Raw types conversions (see :ref:`Raw Type Conversions`). .. index:: compatible type @@ -205,7 +203,6 @@ can be successfully applied to type *T1* to receive type *T2* as a result: identity conversion function types conversion enumeration types conversion - raw types conversion | @@ -245,14 +242,14 @@ effectively transforms into the following: which is then performed as the *toString()* method call. - Any primitive type must convert to a reference value (for boxing see - :ref:`Predefined Numeric Types Conversions`) before the method call + :ref:`Primitive Types Conversions`) before the method call *toString()* is performed. These contexts always have *string* as the target type. *Numeric contexts* apply to the operands of an arithmetic operator. *Numeric contexts* use combinations of predefined numeric types conversions -(see :ref:`Predefined Numeric Types Conversions`), and ensure that each +(see :ref:`Primitive Types Conversions`), and ensure that each argument expression can convert to the target type *T* while the arithmetic operation for the values of type *T* is being defined. @@ -338,7 +335,6 @@ Kinds of Conversion .. meta: frontend_status: Done todo: Narrowing Reference Conversion - note: Only basic checking availiable, not full support of validation - todo: Unchecked Conversion - note: Generics raw types not implemented yet todo: String Conversion - note: Inmplemented in a different but compatible way: spec - toString(), implementation: StringBuilder todo: Forbidden Conversion - note: Not exhaustively tested, should work @@ -367,7 +363,6 @@ categories: numeric types. - Reference types conversions. - String conversions (see :ref:`Operator Contexts`). -- Raw Types Conversion. Any other conversions are forbidden. @@ -378,25 +373,24 @@ Any other conversions are forbidden. numeric type reference type conversion string conversion - raw types conversion conversion | -.. _Predefined Numeric Types Conversions: +.. _Primitive Types Conversions: -Predefined Numeric Types Conversions -==================================== +Primitive Types Conversions +=========================== .. meta: frontend_status: Partly -*Widening conversions* cause no loss of information about the overall magnitude -of a numeric value (except conversions from integer to floating-point types -that can lose some least significant bits of the value if the IEEE 754 -'*round-to-nearest*' mode is used correctly, and the resultant floating-point -value is properly rounded to the integer value). Widening conversions never -cause runtime errors. +For numeric primitive types *widening conversions* cause no loss of +information about the overall magnitude of a numeric value (except conversions +from integer to floating-point types that can lose some least significant bits +of the value if the IEEE 754 '*round-to-nearest*' mode is used correctly, and +the resultant floating-point value is properly rounded to the integer value). +Widening conversions never cause runtime errors. .. index:: widening conversion @@ -430,10 +424,10 @@ cause runtime errors. | *bigint* | *BigInt* | +----------+-----------------------------+ -*Narrowing conversions* (performed in compliance with IEEE 754 like in -other programming languages) can lose information about the overall -magnitude of a numeric value, potentially resulting in the loss of precision -and range. Narrowing conversions never cause runtime errors. +For numeric primitive types *narrowing conversions* (performed in compliance +with IEEE 754 like in other programming languages) can lose information about +the overall magnitude of a numeric value, potentially resulting in the loss of +precision and range. Narrowing conversions never cause runtime errors. .. index:: narrowing conversion @@ -465,7 +459,7 @@ and range. Narrowing conversions never cause runtime errors. - *byte* -> *char*. *Boxing and unboxing* conversions allow converting a reference into a value, -and vice versa, for variables of predefined types. +and vice versa, for variables of primitive types. *Boxing conversions* handle primitive type expressions as expressions of a corresponding reference type. @@ -504,23 +498,25 @@ the same. The table below illustrates both conversions: -+--------------------+--------------------+ -| Boxing | Unboxing | -+====================+====================+ -|*byte* -> *Byte* |*Byte* -> *byte* | -+--------------------+--------------------+ -|*short* -> *Short* |*Short* -> *short* | -+--------------------+--------------------+ -|*char* -> *Char* |*Char* -> *char* | -+--------------------+--------------------+ -|*int* -> *Int* |*Int* -> *int* | -+--------------------+--------------------+ -|*long* -> *Long* |*Long* -> *long* | -+--------------------+--------------------+ -|*float* -> *Float* |*Float* -> *float* | -+--------------------+--------------------+ -|*double* -> *Double*|*Double* -> *double*| -+--------------------+--------------------+ ++----------------------+----------------------+ +| Boxing | Unboxing | ++======================+======================+ +|*byte* -> *Byte* |*Byte* -> *byte* | ++----------------------+----------------------+ +|*short* -> *Short* |*Short* -> *short* | ++----------------------+----------------------+ +|*char* -> *Char* |*Char* -> *char* | ++----------------------+----------------------+ +|*int* -> *Int* |*Int* -> *int* | ++----------------------+----------------------+ +|*long* -> *Long* |*Long* -> *long* | ++----------------------+----------------------+ +|*float* -> *Float* |*Float* -> *float* | ++----------------------+----------------------+ +|*double* -> *Double* |*Double* -> *double* | ++----------------------+----------------------+ +|*boolean* -> *Boolean*|*Boolean* -> *boolean*| ++----------------------+----------------------+ | @@ -605,39 +601,6 @@ See the example below for the illustration of it: | -.. _Generic Types Conversions: - -.. - Generic Types Conversions - ========================= - -.. meta: - frontend_status: Partly - -.. - The conversion of generic types (see :ref:`Generic Declarations`) follows the - widening style of type arguments. - -.. - See the example below for the illustration of it: - .. code-block:: typescript - :linenos: - class Base {} - class Derived extends Base {} - class Generic {} - function foo (d: Generic) { - let b: Generic = d - /* Generic is assigned into Generic */ - } - .. index:: - conversion - generic types conversion - generic type - widening - argument - conversion - | - .. _Function Types Conversions: Function Types Conversions @@ -766,39 +729,6 @@ type: | -.. _Raw Type Conversions: - -Raw Types Conversion -==================== - -.. meta: - frontend_status: Partly - -Assuming that *G* is a generic type declaration with type parameters *n*, - -.. code-block:: typescript - :linenos: - - class|interface G {} - -any instantiation of G (*G* < *Type*:sub:`1`, ``...``, *Type*:sub:`n` >), or -its derived types can convert into *G* <> as follows: - -.. code-block:: typescript - :linenos: - - class|interface H extends G {} - let raw: G<> = new G - raw = new H - -.. index:: - raw types conversion - raw type - generic type - instantiation - derived type - - .. raw:: pdf PageBreak diff --git a/plugins/ets/doc/spec/7_expressions.rst b/plugins/ets/doc/spec/7_expressions.rst index ab41d901f..3f3d349b0 100644 --- a/plugins/ets/doc/spec/7_expressions.rst +++ b/plugins/ets/doc/spec/7_expressions.rst @@ -143,7 +143,7 @@ Chaining Operator ***************** .. meta: - frontend_status: Partly + frontend_status: Done The term *optional chaining operator* (*'?.'*) is used as it effectively covers accesses to an object's property, or calls to functions. If the object @@ -332,7 +332,7 @@ The predefined operators throw runtime errors as follows: - If the right-hand operand expression has the zero value, then integer division (see :ref:`Division`), or integer remainder (see :ref:`Remainder`) operators throw *ArithmeticError*. -- If the boxing conversion (see :ref:`Predefined Numeric Types Conversions`) +- If the boxing conversion (see :ref:`Primitive Types Conversions`) occurs, then the assignment to an array element of a reference type (see :ref:`Array Literal`), method call expression (see :ref:`Method Call Expression`), or prefix/postfix increment/decrement (see @@ -1352,6 +1352,20 @@ function or method. // array literal will be built at rutime } + +Note that if an array is spread while calling a function and appropriate parameter +must be of spread array kind. Spreading array into a sequence of ordinary +parameters is a compile-time error. + +.. code-block:: typescript + :linenos: + + + let an_array = [1, 2] + bar (...an_array) // compile-time error + function bar (n1: number, n2: number) { ... } + + | .. _void Expression: @@ -1492,11 +1506,11 @@ an interface. .. code-block:: abnf methodCallExpression: - objectReference '.' identifier typeArguments? (arguments | arguments? block) + objectReference '.' identifier typeArguments? arguments block? ; The syntax form which has a block associated with the method call is a special -form called trailing lambda call and described here (see :ref:`Trailing Lambda`). +form called trailing lambda call. It is described in detail in :ref:`Trailing Lambda`. A compile-time error occurs if *typeArguments* is present, and any of type arguments are wildcards (see :ref:`Type Arguments`). @@ -1967,7 +1981,12 @@ Array Indexing Expression For an array indexing, a type of *index expression* must be of a numeric type. -A numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +if type of *index expression* is ``number`` or other floating-point type and +its fractional part is different from 0 then it will be runtime error if such +situation is identified during program execution and compile-time one if +detected during compilation. + +A numeric types conversion (see :ref:`Primitive Types Conversions`) is performed on *index expression* to ensure that the resultant type is *int*. A compile-time error occurs otherwise. @@ -2000,6 +2019,13 @@ An illustration is given in the example below: console.log(objects[0].filed) // prints 666 console.log(objects[1].filed) // prints 777 + let an_array = [1, 2, 3] + let element = an_array [3.5] // Compile-time error + function foo (index: number) { + let element = an_array [index] + // Runtime-time error if index is not integer + } + .. index:: array indexing expression @@ -2121,11 +2147,11 @@ A *function call expression* is used to call a function (see .. code-block:: abnf functionCallExpression: - expression ('?.' | typeArguments)? (arguments| arguments? block) + expression ('?.' | typeArguments)? arguments block? ; The special syntactic form which has a block associated with the function -call is called *trailing lambda call*. It is described in detain in +call is called *trailing lambda call*. It is described in detail in :ref:`Trailing Lambda`. A compile-time error occurs if: @@ -2634,7 +2660,7 @@ result of a postfix increment expression is a value, not a variable. If the evaluation of the operand expression completes normally at runtime, then: - The value *1* is added to the value of the variable by using necessary - conversions (see :ref:`Predefined Numeric Types Conversions`); and + conversions (see :ref:`Primitive Types Conversions`); and - The sum is stored back into the variable. .. index:: @@ -2707,7 +2733,7 @@ If evaluation of the operand expression completes at runtime, then: evaluation - The value *1* is subtracted from the value of the variable by using - necessary conversions (see :ref:`Predefined Numeric Types Conversions`); and + necessary conversions (see :ref:`Primitive Types Conversions`); and - The sum is stored back into the variable. Otherwise, the postfix decrement expression completes abruptly, and @@ -2767,7 +2793,7 @@ If evaluation of the operand expression completes normally at runtime, then: conversion - The value *1* is added to the value of the variable by using necessary - conversions (see :ref:`Predefined Numeric Types Conversions`); and + conversions (see :ref:`Primitive Types Conversions`); and - The sum is stored back into the variable. Otherwise, the prefix increment expression completes abruptly, and no @@ -2821,7 +2847,7 @@ result of a prefix decrement expression is a value, not a variable. If evaluation of the operand expression completes normally at runtime, then: - The value *1* is subtracted from the value of the variable by using - necessary conversions (see :ref:`Predefined Numeric Types Conversions`); + necessary conversions (see :ref:`Primitive Types Conversions`); and - The sum is stored back into the variable. @@ -2857,10 +2883,10 @@ Unary Plus frontend_status: Done The type of the operand *expression* with the unary ':math:`+`' operator must -be convertible (see :ref:`Kinds of Conversion`) to a primitive numeric type; +be convertible (see :ref:`Kinds of Conversion`) to a numeric type; a compile-time error occurs otherwise. -The numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +The numeric types conversion (see :ref:`Primitive Types Conversions`) is performed on the operand to ensure that the resultant type is that of the unary plus expression. The result of a unary plus expression is always a value, not a variable (even if the result of the operand expression is a variable). @@ -2871,7 +2897,6 @@ not a variable (even if the result of the operand expression is a variable). expression unary operator conversion - primitive type numeric type compile-time error numeric types conversion @@ -2895,10 +2920,10 @@ Unary Minus todo: let a : Double = Double.Nan; a = -a; (assertion) The type of the operand *expression* with the unary ':math:`--`' operator must -be convertible (see :ref:`Kinds of Conversion`) to a primitive numeric type; a -compile-time error occurs otherwise. +be convertible (see :ref:`Kinds of Conversion`) to a numeric type; +a compile-time error occurs otherwise. -The numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +The numeric types conversion (see :ref:`Primitive Types Conversions`) is performed on the operand to ensure that the resultant type is that of the unary minus expression. The result of a unary minus expression is a value, not a variable (even if the @@ -2915,7 +2940,6 @@ from the same value set as the promoted operand value. operand unary operator conversion - primitive type numeric type predefined numeric types conversion expression @@ -2988,7 +3012,7 @@ The type of the operand *expression* with the unary '~' operator must be convertible (see :ref:`Kinds of Conversion`) to a primitive integer type; a compile-time error occurs otherwise. -The numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +The numeric types conversion (see :ref:`Primitive Types Conversions`) is performed on the operand to ensure that the resultant type is that of the unary bitwise complement expression. @@ -3028,7 +3052,7 @@ The type of the operand *expression* with the unary '``!``' operator must be The unary logical complement expression’s type is *boolean*. -The unboxing conversion (see :ref:`Predefined Numeric Types Conversions`) is +The unboxing conversion (see :ref:`Primitive Types Conversions`) is performed on the operand at runtime if needed. The value of a unary logical complement expression is ``true`` if the @@ -3072,10 +3096,10 @@ The operators '\*', '/', and '%' are *multiplicative operators*. The multiplicative operators group left-to-right. The type of each operand in a multiplicative operator must be convertible (see -:ref:`Contexts and Conversions`) to a primitive numeric type; a compile-time -error occurs otherwise. +:ref:`Contexts and Conversions`) to a numeric type; a compile-time error occurs +otherwise. -The numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +The numeric types conversion (see :ref:`Primitive Types Conversions`) is performed on both operands to ensure that the resultant type is the type of the multiplicative expression. @@ -3087,11 +3111,9 @@ variable (even if the operand expression is a variable). convertibility context conversion - primitive type numeric type multiplicative operator multiplicative expression - primitive type numeric type value unary bitwise complement expression @@ -3212,7 +3234,7 @@ left-hand and right-hand operands (*dividend* and *divisor* respectively). Integer division rounds toward *0*, i.e., the quotient of integer operands *n* and *d*, after a numeric types conversion on both (see -:ref:`Predefined Numeric Types Conversions` for details), is +:ref:`Primitive Types Conversions` for details), is an integer value *q* with the largest possible magnitude that satisfies :math:`|d\cdot{}q|\leq{}|n|`. @@ -3344,7 +3366,7 @@ The remainder operator in |LANG| accepts floating-point operands (unlike in C and C++). The remainder operation on integer operands (for the numeric type conversion -on both see :ref:`Predefined Numeric Types Conversions`) produces a result +on both see :ref:`Primitive Types Conversions`) produces a result value, i.e., :math:`(a/b)*b+(a\%b)` equals *a*. @@ -3476,11 +3498,11 @@ The additive operators group left-to-right. If either operand of the operator is '+' of type *string*, then the operation is a string concatenation. In all other cases, the type of each operand of the operator '+' must be convertible (see :ref:`Kinds of Conversion`) to a -primitive numeric type; a compile-time error occurs otherwise. +numeric type; a compile-time error occurs otherwise. The type of each operand of the binary operator '-' in all cases must be -convertible (see :ref:`Kinds of Conversion`) to a primitive numeric type; -a compile-time error occurs otherwise. +convertible (see :ref:`Kinds of Conversion`) to a numeric type; a compile-time +error occurs otherwise. .. index:: additive expression @@ -3490,7 +3512,6 @@ a compile-time error occurs otherwise. string concatenation operator conversion - primitive type numeric type compile-time error binary operator @@ -3545,7 +3566,7 @@ and produces the sum of such operands. The binary operator '-' performs subtraction, and produces the difference of two numeric operands. -The numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +The numeric types conversion (see :ref:`Primitive Types Conversions`) is performed on the operands. The type of an additive expression on numeric operands is the promoted type of @@ -3697,14 +3718,15 @@ operand in a shift operator; the right-hand operand specifies the shift distance The shift operators group left-to-right. -Numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +Numeric types conversion (see :ref:`Primitive Types Conversions`) is performed separately on each operand to ensure that both operands are of primitive integer type. Note that if the initial type of one or both operands is ``double`` or ``float``, then such operand or operands are truncated to -appropriate integer type first. +appropriate integer type first. If both operands are of type ``bigint`` then +shift operator is applied to bigint operands. A compile-time error occurs if either operand in a shift operator (after unary -numeric promotion) is not a primitive integer type. +numeric promotion) is not a primitive integer type or bigint. .. index:: shift expression @@ -3719,7 +3741,7 @@ numeric promotion) is not a primitive integer type. unary numeric promotion truncation truncated operand - primitive integer type + primitive type The shift expression type is the promoted type of the left-hand operand. @@ -3822,10 +3844,10 @@ Numerical Comparison Operators <, <=, >, and >= frontend_status: Done The type of each operand in a numerical comparison operator must be convertible -(see :ref:`Kinds of Conversion`) to a primitive numeric type; a compile-time +(see :ref:`Kinds of Conversion`) to a numeric type; a compile-time error occurs otherwise. -Numeric types conversions (see :ref:`Predefined Numeric Types Conversions`) are +Numeric types conversions (see :ref:`Primitive Types Conversions`) are performed on each operand as follows: - Signed integer comparison if the converted type of the operand is *int* or *long*. @@ -3981,7 +4003,7 @@ compared: object reference equality operator entity - primitive type entity + primitive type boxing boxed version value equality operator @@ -4157,7 +4179,7 @@ Value Equality Operators for Numeric Types .. meta: frontend_status: Partly -The numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +The numeric types conversion (see :ref:`Primitive Types Conversions`) is performed on the operands of a value equality operator if: - Both are of a numeric type; or @@ -4239,7 +4261,7 @@ The operation is a *boolean equality* if: The boolean equality operators are associative. If one operand is of type *Boolean*, then the unboxing conversion (see -:ref:`Predefined Numeric Types Conversions`) must be performed. +:ref:`Primitive Types Conversions`) must be performed. If both operands (after the unboxing conversion if required) are either ``true`` or ``false``, then the result of ':math:`==`' is ``true``. @@ -4280,7 +4302,7 @@ The operation is a *character equality* if: The character equality operators are associative. If one operand is of the *Char* type, then the unboxing conversion -(see :ref:`Predefined Numeric Types Conversions`) must be performed. +(see :ref:`Primitive Types Conversions`) must be performed. If both operands (after the unboxing conversion where required) contain the same character code, then the result of ':math:`==`' is ``true``. @@ -4364,12 +4386,13 @@ Integer Bitwise Operators &, ^, and | .. meta: frontend_status: Done -The numeric types conversion (see :ref:`Predefined Numeric Types Conversions`) +The numeric types conversion (see :ref:`Primitive Types Conversions`) is first performed on the operands of an operator '&', '^', or '\|' if both such operands are of a type convertible (see :ref:`Kinds of Conversion`) to a primitive integer type. Note that if the initial type of one or both operands is ``double`` or ``float``, then that operand or operands are truncated to the -appropriate integer type first. +appropriate integer type first. If both operands are of type ``bigint`` then +no conversion is required. A bitwise operator expression type is the converted type of its operands. @@ -4387,7 +4410,6 @@ The resultant value of '\|' is the bitwise inclusive OR of the operand values. bitwise exclusive OR operand bitwise inclusive OR operand bitwise AND operand - primitive integer type primitive type integer type conversion @@ -4404,7 +4426,7 @@ Boolean Logical Operators &, ^, and | The type of the bitwise operator expression is *boolean* if both operands of a '&', '^', or '\|' operator are of type *boolean* or *Boolean*. In any case, -the unboxing conversion (see :ref:`Predefined Numeric Types Conversions`) is +the unboxing conversion (see :ref:`Primitive Types Conversions`) is performed on the operands as necessary. If both operand values are ``true``, then the resultant value of '&' is ``true``. @@ -4474,7 +4496,7 @@ Each operand of the *conditional-and* operator must be of type *boolean*, or The left-hand operand expression is first evaluated at runtime. If the result is of the *Boolean* type, then the unboxing conversion (see -:ref:`Predefined Numeric Types Conversions`) is performed as follows: +:ref:`Primitive Types Conversions`) is performed as follows: - If the resultant value is ``false``, then the value of the *conditional-and* expression is ``false``, and the evaluation of the right-hand operand @@ -4483,7 +4505,7 @@ is of the *Boolean* type, then the unboxing conversion (see - If the value of the left-hand operand is ``true``, then the right-hand expression is evaluated. If the result of the evaluation is of type *Boolean*, then it is subjected to the unboxing conversion (see - :ref:`Predefined Numeric Types Conversions`). The resultant value is the + :ref:`Primitive Types Conversions`). The resultant value is the value of the *conditional-and* expression. .. index:: @@ -4547,7 +4569,7 @@ as follows: - If the resultant value is ``false``, then the right-hand expression is evaluated. If the result of the evaluation is of type *Boolean*, then - the *unboxing conversion* (see :ref:`Predefined Numeric Types Conversions`) + the *unboxing conversion* (see :ref:`Primitive Types Conversions`) is performed. The resultant value is the value of the *conditional-or* expression. @@ -5077,7 +5099,7 @@ influences its type determination at runtime: the rules below. Boxing or unboxing conversions are allowed for this conversion (see - :ref:`Predefined Numeric Types Conversions`). + :ref:`Primitive Types Conversions`). The remaining operand expression is not evaluated in this particular evaluation of the conditional expression. @@ -5135,7 +5157,7 @@ The type of a numeric conditional expression is: - *T* if either the second or the third operand is of the primitive type *T*, and the type of the other operand results from the boxing - conversion (see :ref:`Predefined Numeric Types Conversions`) of *T*. + conversion (see :ref:`Primitive Types Conversions`) of *T*. - *short* if one operand’s type is *byte* or *Byte*, and the other’s *short* or *Short*. @@ -5152,8 +5174,8 @@ The type of a numeric conditional expression is: - In other situations, the type of the conditional expression is the promoted type of the second and the third operands after the binary numeric promotion - (see :ref:`Predefined Numeric Types Conversions`) of the operand types. - + (see :ref:`Primitive Types Conversions`) of the operand types. + .. index:: numeric conditional expression primitive type diff --git a/plugins/ets/doc/spec/9_classes.rst b/plugins/ets/doc/spec/9_classes.rst index 8ae76beff..572fb97a8 100644 --- a/plugins/ets/doc/spec/9_classes.rst +++ b/plugins/ets/doc/spec/9_classes.rst @@ -1169,7 +1169,7 @@ Method Declarations classMethodDeclaration: methodOverloadSignature* - methodModifier* identifier signature block? + methodModifier* typeParameters? identifier signature block? ; methodModifier: -- Gitee From 012e547015aed9d1ed57174096ef50c1607235a0 Mon Sep 17 00:00:00 2001 From: Anna Antipina Date: Fri, 27 Oct 2023 11:35:24 +0300 Subject: [PATCH 4/4] [ArkTS] Fix tests after implementing extended conditional expressions Signed-off-by: Anna Antipina --- plugins/ets/doc/spec/15_semantics.rst | 3 ++ .../05.character_types_and_operations/ch.ets | 24 +++++++++++++++ .../ch.params.yaml | 20 +++++++++++++ .../ch_n.params.yaml | 5 ---- .../first_expression_not_boolean.ets | 3 +- .../05.if_statements/if2.params.yaml | 30 +++++++++++++++++++ .../05.if_statements/if_neg.params.yaml | 16 ---------- .../do.params.yaml | 8 +++++ .../neg.params.yaml | 16 ---------- .../while.params.yaml | 8 +++++ .../arktscts-int-amd64-FastVerify.txt | 22 -------------- 11 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch.ets create mode 100644 plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch.params.yaml diff --git a/plugins/ets/doc/spec/15_semantics.rst b/plugins/ets/doc/spec/15_semantics.rst index 02939e59f..3f71b7719 100644 --- a/plugins/ets/doc/spec/15_semantics.rst +++ b/plugins/ets/doc/spec/15_semantics.rst @@ -231,6 +231,9 @@ while doing the |LANG| programming. Extended Conditional Expressions ================================ +.. meta: + frontend_status: Done + |LANG| provides extended semantics for conditional-and and conditional-or expressions for better alignment. It affects the semantics of conditional expressions (see :ref:`Conditional Expressions`), ``while`` statements and diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch.ets b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch.ets new file mode 100644 index 000000000..4910c45ba --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch.ets @@ -0,0 +1,24 @@ +/*--- +Copyright (c) 2021-2023 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: check addition of two bytes +---*/ + +function main() { + const v = {{c.exp}} +} +{% endfor %} diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch.params.yaml new file mode 100644 index 000000000..959ed0774 --- /dev/null +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch.params.yaml @@ -0,0 +1,20 @@ +# Copyright (c) 2021-2023 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: + - exp: c'2' & c'2' + - exp: c'2' && c'2' + - exp: c'2' | c'2' + - exp: c'2' || c'2' + - exp: "!c'2' && !c'2'" diff --git a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.params.yaml b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.params.yaml index 24bd9072f..76f3a63d6 100644 --- a/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.params.yaml +++ b/plugins/ets/tests/ets-templates/03.types/07.value_types/05.character_types_and_operations/ch_n.params.yaml @@ -19,9 +19,4 @@ cases: - exp: c'2' >> c'2' - exp: c'2' >>> c'2' - exp: c'2' << c'2' - - exp: c'2' & c'2' - - exp: c'2' && c'2' - - exp: c'2' | c'2' - - exp: c'2' || c'2' - exp: c'2' ^ c'2' - - exp: "!c'2' && !c'2'" diff --git a/plugins/ets/tests/ets-templates/07.expressions/29.conditional_expressions/first_expression_not_boolean.ets b/plugins/ets/tests/ets-templates/07.expressions/29.conditional_expressions/first_expression_not_boolean.ets index b3b2d1d2e..d82beda36 100644 --- a/plugins/ets/tests/ets-templates/07.expressions/29.conditional_expressions/first_expression_not_boolean.ets +++ b/plugins/ets/tests/ets-templates/07.expressions/29.conditional_expressions/first_expression_not_boolean.ets @@ -21,5 +21,6 @@ tags: [compile-only, negative] function cond(): void {} function main(): void { - let a = cond() ? 0 : 1; + let a = cond() ? 1 : 0; + return a; } diff --git a/plugins/ets/tests/ets-templates/08.statements/05.if_statements/if2.params.yaml b/plugins/ets/tests/ets-templates/08.statements/05.if_statements/if2.params.yaml index cc402a6c3..386cf7b19 100644 --- a/plugins/ets/tests/ets-templates/08.statements/05.if_statements/if2.params.yaml +++ b/plugins/ets/tests/ets-templates/08.statements/05.if_statements/if2.params.yaml @@ -133,3 +133,33 @@ cases: else return retcode("FF") } + + - use: |- + if (i) return 0; + else return j; + + - use: |- + if (new Object()) return 0; + else return j; + + - use: |- + if ("xyz") return 0; + else return j; + + - use: |- + if (!"") return 0; + else return j; + + - use: |- + if (!null) return 0; + else return j; + + - use: |- + if ([1, 1]) return 0; + else return j; + + - use: |- + let k: int[] = []; + if (!k) return 0; + else return j; + diff --git a/plugins/ets/tests/ets-templates/08.statements/05.if_statements/if_neg.params.yaml b/plugins/ets/tests/ets-templates/08.statements/05.if_statements/if_neg.params.yaml index b19ec808e..7ee892375 100644 --- a/plugins/ets/tests/ets-templates/08.statements/05.if_statements/if_neg.params.yaml +++ b/plugins/ets/tests/ets-templates/08.statements/05.if_statements/if_neg.params.yaml @@ -13,22 +13,6 @@ --- cases: - - use: |- - // wrong type - if (i) return 1; - - - use: |- - // wrong type - if (new Object()) return 1; - - - use: |- - // wrong type - if ("xyz") return 1; - - - use: |- - // wrong type - if (!null) return 1; - - use: |- // missing statement in then branch if (i == j) diff --git a/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/do.params.yaml b/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/do.params.yaml index 864e870b0..f92b77994 100644 --- a/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/do.params.yaml +++ b/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/do.params.yaml @@ -41,3 +41,11 @@ cases: i = j; } while (j < 3) if (i == 1 && j == 4) return 0; + + - use: |- + do {i--} while (i+j) + if (i == -1) return 0; + + - use: |- + do {i--} while (i & j) + if (i == 0) return 0; diff --git a/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/neg.params.yaml b/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/neg.params.yaml index d24cf73a4..be3dd17a4 100644 --- a/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/neg.params.yaml +++ b/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/neg.params.yaml @@ -13,22 +13,6 @@ --- cases: - - use: |- - // wrong type - while (1) {} - - - use: |- - // wrong type - do {} while (1) - - - use: |- - // wrong type - while (i & j) {} - - - use: |- - // wrong type - do {} while (i & j) - - use: |- // missing parentheses while i > j {} diff --git a/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/while.params.yaml b/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/while.params.yaml index 923f33217..1f1f81ec2 100644 --- a/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/while.params.yaml +++ b/plugins/ets/tests/ets-templates/08.statements/07.while_statements_and_do_statements/while.params.yaml @@ -37,3 +37,11 @@ cases: - use: |- while(++i < 10); { i-- } if (i == 9) return 0; + + - use: |- + while (i+j) { i-- } + if (i == -1) return 0; + + - use: |- + while (i & j) {i--} + if (i == 0) return 0; diff --git a/plugins/ets/tests/scripts/CtsTools/skiplists/arktscts-int-amd64-FastVerify.txt b/plugins/ets/tests/scripts/CtsTools/skiplists/arktscts-int-amd64-FastVerify.txt index 56dc431dc..6f0e4e658 100644 --- a/plugins/ets/tests/scripts/CtsTools/skiplists/arktscts-int-amd64-FastVerify.txt +++ b/plugins/ets/tests/scripts/CtsTools/skiplists/arktscts-int-amd64-FastVerify.txt @@ -846,28 +846,6 @@ 03.types/04.value_types/01.integer_types_and_operations/subtraction/subtraction_ushort_7 # Not implemented 03.types/04.value_types/01.integer_types_and_operations/subtraction/subtraction_ushort_8 # Not implemented 03.types/04.value_types/01.integer_types_and_operations/subtraction/subtraction_ushort_9 # Not implemented -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_byte_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_byte_1 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_byte_2 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_char_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_char_1 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_int_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_int_1 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_int_2 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_long_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_long_1 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_long_2 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_short_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_short_1 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_short_2 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_ubyte_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_ubyte_1 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_uint_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_uint_1 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_ulong_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_ulong_1 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_ushort_0 # TypeError: Condition must be of type boolean -03.types/04.value_types/01.integer_types_and_operations/ternary/ternary_ushort_1 # TypeError: Condition must be of type boolean 03.types/04.value_types/01.integer_types_and_operations/unary_minus/unary_minus_char_2 # TypeError: Method MAX_VALUE does not exist on this type. 03.types/04.value_types/01.integer_types_and_operations/unary_minus/unary_minus_char_3 # TypeError: Method MIN_VALUE does not exist on this type. 03.types/04.value_types/01.integer_types_and_operations/unary_minus/unary_minus_ubyte_0 # Not implemented -- Gitee