Skip to content

Fix Positioned#cloneIn #13627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2021
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
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Positioned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src

private var mySpan: Span = _

private var mySource: SourceFile = src

/** A unique identifier in case -Yshow-tree-ids, or -Ydebug-tree-with-id
* is set, -1 otherwise.
*/
Expand All @@ -48,7 +50,8 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src

span = envelope(src)

val source: SourceFile = src
def source: SourceFile = mySource

def sourcePos(using Context): SourcePosition = source.atSpan(span)

/** This positioned item, widened to `SrcPos`. Used to make clear we only need the
Expand Down Expand Up @@ -127,7 +130,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
def cloneIn(src: SourceFile): this.type = {
val newpd: this.type = clone.asInstanceOf[this.type]
newpd.allocateId()
// assert(newpd.uniqueId != 2208, s"source = $this, ${this.uniqueId}, ${this.span}")
newpd.mySource = src
newpd
}

Expand Down
2 changes: 2 additions & 0 deletions tests/run/splice-position.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Test$.main(Test.scala:3)
Test$.main(Test.scala:4)
4 changes: 4 additions & 0 deletions tests/run/splice-position/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test:
def main(args: Array[String]) =
try assertTrue(1 == 2) catch e => println(e.getStackTrace()(0))
try assertTrue(1 == 3) catch e => println(e.getStackTrace()(0))
7 changes: 7 additions & 0 deletions tests/run/splice-position/macros.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted.{Quotes, Expr, quotes}

inline def assertTrue(cond: Boolean) =
${ assertTrueImpl('cond) }

def assertTrueImpl(cond: Expr[Boolean])(using Quotes) =
'{ if (!$cond) throw new Error(${'{""}}) }