Skip to content

Commit

Permalink
Merge pull request #19 from metasim/metasim/bug17
Browse files Browse the repository at this point in the history
Proposed fix to bug #17
  • Loading branch information
lihaoyi authored Aug 3, 2016
2 parents 017d3fc + ef7642f commit 98edb02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
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================")
}
}

0 comments on commit 98edb02

Please sign in to comment.