diff --git a/static_core/plugins/ets/stdlib/escompat/Date.ets b/static_core/plugins/ets/stdlib/escompat/Date.ets index c96e782250df3d267aca7cbe83f036317791331d..7a5c9989ef41bbf60b29b4e7145f88b7fb114cd5 100644 --- a/static_core/plugins/ets/stdlib/escompat/Date.ets +++ b/static_core/plugins/ets/stdlib/escompat/Date.ets @@ -2025,7 +2025,7 @@ class ISODateParser { const literalText = this.dateStr.substring(startPos, endPos) for (const literalChar of literalText) { - if (!Char.isDecDigit(literalChar)) { + if (!Char.isDecDigit(literalChar.charAt(0))) { throw new ISODateParseError() } } diff --git a/static_core/plugins/ets/stdlib/std/core/String.ets b/static_core/plugins/ets/stdlib/std/core/String.ets index d9bbe6b3f4dc8ff242438e12b6082e3a8629b3ac..bcd2a09c2c74a4d48ea0ebcb9a306cb62a5830d6 100644 --- a/static_core/plugins/ets/stdlib/std/core/String.ets +++ b/static_core/plugins/ets/stdlib/std/core/String.ets @@ -139,6 +139,10 @@ export final class String extends Object implements Comparable, JSONable return this.getLength().toDouble() } + public charAtString(index: int): string { + return this.charAt(index as number).toString(); + } + /** * Getter for char at some index * diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/09.for_of_statements/for_of.params.yaml b/static_core/plugins/ets/tests/ets-templates/08.statements/09.for_of_statements/for_of.params.yaml index 504de9f26c16de381f8959112910de54cb6d3ff2..244ff48334664a014c6ebc778f87dd3711ed2e45 100644 --- a/static_core/plugins/ets/tests/ets-templates/08.statements/09.for_of_statements/for_of.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/09.for_of_statements/for_of.params.yaml @@ -77,32 +77,36 @@ cases: assertEQ( res, "1234" ) - use: |- - const ch: char = c'X' + const ch: string = 'X' for (let ch of "A" + "B" + "CD") { res += ch - ch = c' ' + ch = ' ' res += ch } assertEQ( res, "A B C D " ) - use: |- - let ch: char + let ch: string for (ch of "ABCD") res += ch assertEQ( res, "ABCD" ) - use: |- - let ch: char + let ch: string for (ch of "ABCD") { res += ch - ch = c' ' + ch = ' ' res += ch } assertEQ( res, "A B C D " ) - use: |- - let foo: () => String = ():String => { return "ABCD" } - for (let ch of foo()) res += ++ch - assertEQ( res, "BCDE" ) + res = "" + let foo: () => String = ():String => { return "ABCD" } + for (let str of foo()) { + let ch = str.charAt(0); + res += ++ch; + } + assertEQ( res, "BCDE" ) - use: |- let arr: Long[] = new Long[3] diff --git a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/06.type_inference/01.smart_types/for_of_stmt.params.yaml b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/06.type_inference/01.smart_types/for_of_stmt.params.yaml index 3afc33611df2515007e3c5370cf73e7411a2119c..3bb4a03f4f1da166c8036d2317c3ff724e414f4c 100644 --- a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/06.type_inference/01.smart_types/for_of_stmt.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/06.type_inference/01.smart_types/for_of_stmt.params.yaml @@ -13,10 +13,10 @@ cases: - code: |- - let v: char|null + let v: string|null let res: char for (v of 'a') { - res = v + res = v!.charAt(0); } return res == c'a' ? 0 : 1 diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/07.statements/01.for-of_type_annotation/for_of.params.yaml b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/07.statements/01.for-of_type_annotation/for_of.params.yaml index 481c35cdf33626e67da03d0911a846a1ce3e22b5..815321dffddecab43b141252c7dd4ce30f738fcf 100644 --- a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/07.statements/01.for-of_type_annotation/for_of.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/07.statements/01.for-of_type_annotation/for_of.params.yaml @@ -35,21 +35,21 @@ cases: - use: |- // empty string - for (let v: char of "") res += v + for (let v: string of "") res += v.charAt(0) if (res == "") return 0; - decl: |- // empty nullable string let s: string|null = "" use: |- - for (let v: char of s!) res += v + for (let v: string of s!) res += v.charAt(0) if (res == "") return 0; - decl: |- // empty nullable string let s: string|undefined = "" use: |- - for (const v: char of s!) res += v + for (const v: string of s!) res += v.charAt(0) if (res == "") return 0; - decl: |- @@ -208,7 +208,7 @@ cases: let arr: string[] = ["ABC", "DEF", "GHJ"] use: |- for (let v: string of arr) - for (let q: char of v) + for (let q: string of v) res += q + " " if (res == "A B C D E F G H J ") return 0 @@ -221,13 +221,13 @@ cases: - use: |- // expression with strings - let ch: char = c'X' - for (let ch: char of "A" + "B" + "CD") { + let ch: string = 'X' + for (let ch: string of "A" + "B" + "CD") { res += ch - ch = c' ' + ch = ' ' res += ch } - if (res == "A B C D " && ch == c'X') return 0; + if (res == "A B C D " && ch == 'X') return 0; - decl: |- function foo(s: T): T[] { @@ -237,8 +237,8 @@ cases: // function with generics, String array for (let v: String of foo("AZ")) { res += "-" - for (let q: Char of v) { - res += q.unboxed() + for (let q: string of v) { + res += (q.charAt(0) as Char).unboxed() } } if (res == "-AZ-AZ-AZ") return 0; diff --git a/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-01.ets b/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-01.ets index 3bd7ed29201fc017173355693d10ec3b852788bf..fa62c474896c7fb562612448603fc53a37f10f27 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-01.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-01.ets @@ -19,11 +19,11 @@ tags: [] ---*/ function main() { - let ch : char = c'z'; + let ch : string = 'z'; let index : int = 0; let result : int = 0; let testStr : String = "a string object"; - let testArray : char[] = [c'a', c' ', c's', c't', c'r', c'i', c'n', c'g', c' ', c'o', c'b', c'j', c'e', c'c', c't']; + let testArray : string[] = ['a', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', 'o', 'b', 'j', 'e', 'c', 't']; for (ch of testStr) { if (ch != testArray[index]) { console.log("Incorrect element at index : " + index); diff --git a/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-02.ets b/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-02.ets index b117da4bda68e4e7bbbe5968e32dbea83dcea62e..2b6507eab5d834fe8151eab5662c71b931d7a862 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-02.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-02.ets @@ -19,7 +19,7 @@ tags: [] ---*/ function main() : int { - let tmp : char = c'z'; + let tmp : string = 'z'; let initialString : String = "abcdef"; let workString : String = ""; for (tmp of initialString) { diff --git a/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-03.ets b/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-03.ets index ec86dac17604054e77dfe2c6691e4e1df0501d45..43ed100ebf4a3f7d1f66e5633893cedbf202b53c 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-03.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-03.ets @@ -23,11 +23,11 @@ function doit(ch : char) : FixedArray { } function main() : int { - let tmp : char = c'z'; + let tmp : string = 'z'; let initialString : String = "abcdef"; let workString : String = ""; for (tmp of initialString) { - workString = workString + new String(doit(tmp)); + workString = workString + new String(doit(tmp.charAt(0))); } if (workString == "aabbccddeeff") { diff --git a/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-04.ets b/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-04.ets index bae8b01ee283ac3aa8ac92d386130d436786ca13..6a2524d44311b2c19607b13196a5c8533f4d4048 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-04.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/spec/17.Experimental_Features/Iterable_Types/for-of-s01-string-04.ets @@ -20,7 +20,7 @@ tags: [] function main() : int { let index : int = 0; - let tmp : char = c'z'; + let tmp : string = 'z'; let initialString : String = ""; for (tmp of initialString) { index++;