Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ object Impls{
def text[T: c.WeakTypeTag](c: Compat.Context)(v: c.Expr[T]): c.Expr[sourcecode.Text[T]] = {
import c.universe._
val fileContent = new String(v.tree.pos.source.content)
val start = v.tree.collect{case tree => tree.pos.startOrPoint}.min
val start = v.tree.collect {
case treeVal => treeVal.pos match {
case NoPosition ⇒ Int.MaxValue
case p ⇒ p.startOrPoint
}
}.min
val g = c.asInstanceOf[reflect.macros.runtime.Context].global
val parser = g.newUnitParser(fileContent.drop(start))
parser.expr()
Expand Down Expand Up @@ -185,4 +190,4 @@ object Impls{
}.mkString.dropRight(1)
c.Expr[T](q"""${c.prefix}($renderedPath)""")
}
}
}
11 changes: 11 additions & 0 deletions sourcecode/shared/src/test/scala/sourcecode/Regressions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sourcecode

object Regressions {
def bug17() = {
val text = sourcecode.Text(Seq(1).map(_+1))
assert(text.source == "Seq(1).map(_+1)")
}
def main() = {
bug17()
}
}
2 changes: 2 additions & 0 deletions sourcecode/shared/src/test/scala/sourcecode/Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ object Tests{
DebugName.main()
println("================Debug Lite================")
DebugLite.main()
println("================Regressions===============")
Regressions.main()
println("================Test Ended================")
}
}