From 5ab1c5aaffaf88f9d7a3380cb34cb86f66384bd4 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 5 Dec 2021 08:15:00 +0800 Subject: [PATCH 1/3] . --- fansi/src/fansi/Fansi.scala | 2 +- fansi/test/src/fansi/FansiTests.scala | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fansi/src/fansi/Fansi.scala b/fansi/src/fansi/Fansi.scala index 15df9b4..9cf6f69 100644 --- a/fansi/src/fansi/Fansi.scala +++ b/fansi/src/fansi/Fansi.scala @@ -224,7 +224,7 @@ object Str{ * Make the construction of [[fansi.Str]]s from `String`s and other * `CharSequence`s automatic */ - implicit def implicitApply(raw: CharSequence): fansi.Str = apply(raw) + implicit def implicitApply(raw: String with Singleton): fansi.Str = apply(raw) /** * Regex that can be used to identify Ansi escape patterns in a string. diff --git a/fansi/test/src/fansi/FansiTests.scala b/fansi/test/src/fansi/FansiTests.scala index 0e2d3a6..098f281 100644 --- a/fansi/test/src/fansi/FansiTests.scala +++ b/fansi/test/src/fansi/FansiTests.scala @@ -276,7 +276,7 @@ object FansiTests extends TestSuite{ println() } test - check( - "#" + fansi.Color.True(127, 126, 0)("lol") + "omg" + fansi.Color.True(127, 126, 0)("wtf") + fansi.Str("#") ++ fansi.Color.True(127, 126, 0)("lol") ++ "omg" ++ fansi.Color.True(127, 126, 0)("wtf") ) test - square(for(i <- 0 to 255) yield fansi.Color.True(i,i,i)) @@ -439,6 +439,10 @@ object FansiTests extends TestSuite{ ) } } + test("implicitConstructorOnlyForLiterals"){ + compileError("""{val x = ""; x: fansi.Str }""") + "": fansi.Str + } // test("perf"){ // val input = s"+++$R---$G***$B///" * 1000 // From 49b27507a5f37262ef2426bff06e8a73aba88f52 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 5 Dec 2021 08:51:58 +0800 Subject: [PATCH 2/3] . --- fansi/test/src/fansi/FansiTests.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fansi/test/src/fansi/FansiTests.scala b/fansi/test/src/fansi/FansiTests.scala index 098f281..0925790 100644 --- a/fansi/test/src/fansi/FansiTests.scala +++ b/fansi/test/src/fansi/FansiTests.scala @@ -440,7 +440,9 @@ object FansiTests extends TestSuite{ } } test("implicitConstructorOnlyForLiterals"){ - compileError("""{val x = ""; x: fansi.Str }""") + if (scala.util.Properties.versionNumberString.startsWith("2.")){ + compileError("""{val x = ""; x: fansi.Str }""") + } "": fansi.Str } // test("perf"){ From 28a5245deb3fa49dcff03b38e70d7cd578d121ed Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 5 Dec 2021 09:03:50 +0800 Subject: [PATCH 3/3] . --- fansi/test/src-2/fansi/Scala2FansiTests.scala | 16 ++++++++++++++++ fansi/test/src/fansi/FansiTests.scala | 4 +--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 fansi/test/src-2/fansi/Scala2FansiTests.scala diff --git a/fansi/test/src-2/fansi/Scala2FansiTests.scala b/fansi/test/src-2/fansi/Scala2FansiTests.scala new file mode 100644 index 0000000..678a6ef --- /dev/null +++ b/fansi/test/src-2/fansi/Scala2FansiTests.scala @@ -0,0 +1,16 @@ +package test.fansi + +import utest._ + + +object Scala2FansiTests extends TestSuite{ + + val tests = TestSuite{ + + test("implicitConstructorOnlyForLiterals"){ + compileError("""{val x = ""; x: fansi.Str }""") + "": fansi.Str + } + } +} + diff --git a/fansi/test/src/fansi/FansiTests.scala b/fansi/test/src/fansi/FansiTests.scala index 0925790..ffe3ed6 100644 --- a/fansi/test/src/fansi/FansiTests.scala +++ b/fansi/test/src/fansi/FansiTests.scala @@ -440,9 +440,7 @@ object FansiTests extends TestSuite{ } } test("implicitConstructorOnlyForLiterals"){ - if (scala.util.Properties.versionNumberString.startsWith("2.")){ - compileError("""{val x = ""; x: fansi.Str }""") - } + "": fansi.Str } // test("perf"){