Skip to content

Commit ef7642f

Browse files
author
Simeon H.K. Fitch
committed
Proposed fix to bug #17
1 parent 017d3fc commit ef7642f

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ object Impls{
128128
def text[T: c.WeakTypeTag](c: Compat.Context)(v: c.Expr[T]): c.Expr[sourcecode.Text[T]] = {
129129
import c.universe._
130130
val fileContent = new String(v.tree.pos.source.content)
131-
val start = v.tree.collect{case tree => tree.pos.startOrPoint}.min
131+
val start = v.tree.collect {
132+
case treeVal => treeVal.pos match {
133+
case NoPosition Int.MaxValue
134+
case p p.startOrPoint
135+
}
136+
}.min
132137
val g = c.asInstanceOf[reflect.macros.runtime.Context].global
133138
val parser = g.newUnitParser(fileContent.drop(start))
134139
parser.expr()
@@ -185,4 +190,4 @@ object Impls{
185190
}.mkString.dropRight(1)
186191
c.Expr[T](q"""${c.prefix}($renderedPath)""")
187192
}
188-
}
193+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package sourcecode
2+
3+
object Regressions {
4+
def bug17() = {
5+
val text = sourcecode.Text(Seq(1).map(_+1))
6+
assert(text.source == "Seq(1).map(_+1)")
7+
}
8+
def main() = {
9+
bug17()
10+
}
11+
}

sourcecode/shared/src/test/scala/sourcecode/Tests.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ object Tests{
3030
DebugName.main()
3131
println("================Debug Lite================")
3232
DebugLite.main()
33+
println("================Regressions===============")
34+
Regressions.main()
3335
println("================Test Ended================")
3436
}
3537
}

0 commit comments

Comments
 (0)