diff --git a/modules/internal/ChapelArray.chpl b/modules/internal/ChapelArray.chpl index 7772040a3f5f..50fdbe0b954b 100644 --- a/modules/internal/ChapelArray.chpl +++ b/modules/internal/ChapelArray.chpl @@ -2210,6 +2210,7 @@ module ChapelArray { // How to cast arrays to strings @chpldoc.nodoc + @deprecated(notes="casting arrays to string is deprecated; please use 'try! \"%?\".format()' from IO.FormattedIO instead") operator :(x: [], type t:string) { import IO.FormattedIO.string; return try! "%?".format(x); diff --git a/test/arrays/cast/cast-to-string.chpl b/test/arrays/cast/cast-to-string.chpl new file mode 100644 index 000000000000..c526def62470 --- /dev/null +++ b/test/arrays/cast/cast-to-string.chpl @@ -0,0 +1,16 @@ +var a = [i in 1..10] i; + +operator :(arr: [], type t:string) { + var s = "---"; + var first = true; + for x in arr { + if first + then first = false; + else s += " "; + s += x:string; + }; + s += "---"; + return s; +} + +writeln(a:string); diff --git a/test/arrays/cast/cast-to-string.good b/test/arrays/cast/cast-to-string.good new file mode 100644 index 000000000000..0ed8702235b2 --- /dev/null +++ b/test/arrays/cast/cast-to-string.good @@ -0,0 +1 @@ +---1 2 3 4 5 6 7 8 9 10--- diff --git a/test/arrays/cast/castArrToString.chpl b/test/arrays/cast/castArrToString.chpl deleted file mode 100644 index 5d2f4546c173..000000000000 --- a/test/arrays/cast/castArrToString.chpl +++ /dev/null @@ -1,6 +0,0 @@ -var bb = [{1..3}, {1..5}]; -writeln(bb); -writeln(bb.type:string); -var b = bb: string; -writeln(b); -writeln(b.type: string); diff --git a/test/arrays/cast/castArrToString.good b/test/arrays/cast/castArrToString.good deleted file mode 100644 index 8e90f759004e..000000000000 --- a/test/arrays/cast/castArrToString.good +++ /dev/null @@ -1,4 +0,0 @@ -{1..3} {1..5} -[domain(1,int(64),one)] domain(1,int(64),one) -{1..3} {1..5} -string diff --git a/test/arrays/cast/castArrToString2.chpl b/test/arrays/cast/castArrToString2.chpl deleted file mode 100644 index 3819defe6715..000000000000 --- a/test/arrays/cast/castArrToString2.chpl +++ /dev/null @@ -1,6 +0,0 @@ -var bb = [{1..3, 1..3}, {1..5, 1..5}]; -writeln(bb); -writeln(bb.type:string); -var b = bb: string; -writeln(b); -writeln(b.type: string); // [domain(1,int(64),false)] [domain(1,int(64),false)] string diff --git a/test/arrays/cast/castArrToString2.good b/test/arrays/cast/castArrToString2.good deleted file mode 100644 index acbd5bab3b59..000000000000 --- a/test/arrays/cast/castArrToString2.good +++ /dev/null @@ -1,4 +0,0 @@ -{1..3, 1..3} {1..5, 1..5} -[domain(1,int(64),one)] domain(2,int(64),one) -{1..3, 1..3} {1..5, 1..5} -string diff --git a/test/arrays/cast/promoted-cast-to-string.chpl b/test/arrays/cast/promoted-cast-to-string.chpl new file mode 100644 index 000000000000..71b01c4bdb1d --- /dev/null +++ b/test/arrays/cast/promoted-cast-to-string.chpl @@ -0,0 +1,18 @@ +record R { + var x: int; + + operator: (r: R, type t:string) { + return "-" + r.x:string + "-"; + } +} + +proc string.init=(r: R) { + init this; + this = r:string; +} + +const d = {1..10}, + a = [i in d] new R(i), + b: [d] string = a; + +writeln(b); diff --git a/test/arrays/cast/promoted-cast-to-string.good b/test/arrays/cast/promoted-cast-to-string.good new file mode 100644 index 000000000000..13d40362925a --- /dev/null +++ b/test/arrays/cast/promoted-cast-to-string.good @@ -0,0 +1 @@ +-1- -2- -3- -4- -5- -6- -7- -8- -9- -10- diff --git a/test/deprecated/IO/array-string-cast.chpl b/test/deprecated/IO/array-string-cast.chpl new file mode 100644 index 000000000000..61d08a7ad9f6 --- /dev/null +++ b/test/deprecated/IO/array-string-cast.chpl @@ -0,0 +1,2 @@ +const x: [1..10] int; +writeln(x:string); diff --git a/test/deprecated/IO/array-string-cast.good b/test/deprecated/IO/array-string-cast.good new file mode 100644 index 000000000000..8862bc54a395 --- /dev/null +++ b/test/deprecated/IO/array-string-cast.good @@ -0,0 +1,2 @@ +array-string-cast.chpl:2: warning: casting arrays to string is deprecated; please use 'try! "%?".format()' from IO.FormattedIO instead +0 0 0 0 0 0 0 0 0 0 diff --git a/tools/mason/MasonTest.chpl b/tools/mason/MasonTest.chpl index 473cd3571432..caad5685e871 100644 --- a/tools/mason/MasonTest.chpl +++ b/tools/mason/MasonTest.chpl @@ -591,11 +591,11 @@ proc runAndLog(executable, fileName, ref result, reqNumLocales: int = numLocales // (albeit wasteful) thing we can do here is just cast the lists to // array here. // - if testNames.size != 0 then testNamesStr = testNames.toArray(): string; - if failedTestNames.size != 0 then failedTestNamesStr = failedTestNames.toArray(): string; - if erroredTestNames.size != 0 then erroredTestNamesStr = erroredTestNames.toArray(): string; - if testsPassed.size != 0 then passedTestStr = testsPassed.toArray(): string; - if skippedTestNames.size != 0 then skippedTestNamesStr = skippedTestNames.toArray(): string; + if testNames.size != 0 then testNamesStr = try! "%?".format(testNames.toArray()); + if failedTestNames.size != 0 then failedTestNamesStr = try! "%?".format(failedTestNames.toArray()); + if erroredTestNames.size != 0 then erroredTestNamesStr = try! "%?".format(erroredTestNames.toArray()); + if testsPassed.size != 0 then passedTestStr = try! "%?".format(testsPassed.toArray()); + if skippedTestNames.size != 0 then skippedTestNamesStr = try! "%?".format(skippedTestNames.toArray()); var exec = spawn([executable, "-nl", reqNumLocales: string, "--testNames", testNamesStr,"--failedTestNames", failedTestNamesStr, "--errorTestNames", erroredTestNamesStr, "--ranTests", passedTestStr, "--skippedTestNames",