Skip to content
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

Wrong position of quote content #13626

Closed
mbovel opened this issue Sep 28, 2021 · 0 comments · Fixed by #13627
Closed

Wrong position of quote content #13626

mbovel opened this issue Sep 28, 2021 · 0 comments · Fixed by #13627
Assignees
Milestone

Comments

@mbovel
Copy link
Member

mbovel commented Sep 28, 2021

Compiler version

8246a7b

Minimized code

macros.scala:

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(${'{""}}) }

Test.scala:

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))

Output

Test$.main(Test.scala:5)
Test$.main(Test.scala:5)

Expectation

Test$.main(Test.scala:3)
Test$.main(Test.scala:4)

Cause

The content of the inner quote gets a wrong position:

new Error@<macros.scala:7>@<macros.scala:7>@<macros.scala:7>(
	""@<Test.scala:5>@<macros.scala:7>
)@<macros.scala:7>

I think that this is due to Positioned#cloneIn not updating Positioned#source (origin: #9900).

@mbovel mbovel self-assigned this Sep 28, 2021
mbovel added a commit that referenced this issue Sep 28, 2021
mbovel added a commit that referenced this issue Sep 28, 2021
mbovel added a commit that referenced this issue Sep 30, 2021
mbovel added a commit to dotty-staging/dotty that referenced this issue Sep 30, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants