Skip to content

Commit

Permalink
Try to use scala/scala3#5870
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Mar 13, 2019
1 parent 871f7b4 commit 8a2cdda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 2 additions & 3 deletions sourcecode/shared/src/main/dotty/sourcecode/Macros.scala
Expand Up @@ -195,9 +195,8 @@ object Macros {

def text[T: Type](v: Expr[T])(implicit c: Reflection): Expr[sourcecode.Text[T]] = {
import c._
import scala.quoted.Toolbox.Default._
val txt = v.show
'(sourcecode.Text[T](~v, ~txt.toExpr))
val txt = v.unseal.underlyingArgument.pos.sourceCode.toString.toExpr
'(sourcecode.Text[T](~v, ~txt))
}

sealed trait Chunk
Expand Down
13 changes: 5 additions & 8 deletions sourcecode/shared/src/test/scala/sourcecode/TextTests.scala
Expand Up @@ -5,14 +5,11 @@ object TextTests {
assert(foo(1) == (1, "1"))
val bar = Seq("lols")
assert(foo(bar) == (Seq("lols"), "bar"))
// FIXME Don't pass on dotty (second element not ok)
if (TestUtil.isDotty) {
assert(foo(Symbol("lol").toString * 2)._1 == "'lol'lol")
assert(foo{println("Hello"); Symbol("lol").toString * 2}._1 == "'lol'lol")
} else {
assert(foo(Symbol("lol").toString * 2) == ("'lol'lol", "Symbol(\"lol\").toString * 2"))
assert(foo{println("Hello"); Symbol("lol").toString * 2} == ("'lol'lol", "Symbol(\"lol\").toString * 2"))
}
assert(
foo(Symbol("lol").toString * 2) == ("'lol'lol", "Symbol(\"lol\").toString * 2"),
s"Expected: ${("'lol'lol", "Symbol(\"lol\").toString * 2")}, got: ${foo(Symbol("lol").toString * 2)}"
)
assert(foo{println("Hello"); Symbol("lol").toString * 2} == ("'lol'lol", "Symbol(\"lol\").toString * 2"))
}
def foo[T](v: sourcecode.Text[T]) = (v.value, v.source)
}

0 comments on commit 8a2cdda

Please sign in to comment.