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

Regression from March: Incorrect quoted.Type instance required in quotes subclassing an inner trait #17293

Closed
neko-kai opened this issue Apr 17, 2023 · 6 comments · Fixed by #18239
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@neko-kai
Copy link
Contributor

neko-kai commented Apr 17, 2023

Compiler version

3.3.1-RC1-bin-20230407-bcaa1ca-NIGHTLY and 3.3.1-RC1-bin-20230416-2f4cc4c-NIGHTLY

Minimized code

https://scastie.scala-lang.org/E3WYTt73Ryqc3pzCY1xapQ

import scala.quoted.{Expr, Quotes, Type, quotes}

trait OuterTrait {
  trait X
}

def exampleMacro[T <: OuterTrait: Type](expr: Expr[T])(using Quotes): Expr[OuterTrait#X] = {
  '{
    val prefix: T = ${ expr }
    new prefix.X {}
  }
}

Output

[error] -- Error: exampleMacro.scala:12:19
[error] 12 |    new prefix.X {}
[error]    |                   ^
[error]    |Reference to T#X within quotes requires a given scala.quoted.Type[T#X] in scope.

Expectation

Expected to compile as on commit 7262437 (version 3.3.1-RC1-bin-20230331-7262437-NIGHTLY, https://scastie.scala-lang.org/y7mN6SA1REKvXAqIIEAbqw).

Constraint Type[T#X] is unwriteable since it's an abstract type projection and cannot be satisfied.

@neko-kai neko-kai added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 17, 2023
@jchyb jchyb added area:metaprogramming:quotes Issues related to quotes and splices regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 18, 2023
@jchyb
Copy link
Contributor

jchyb commented Apr 18, 2023

It appears that the bisect script points to f035f10 as the "first bad commit"

@neko-kai
Copy link
Contributor Author

neko-kai commented May 1, 2023

@nicolasstucki Could you please look into this regression when you have the time? It wouldn't let us update a Scala 3.2 project to 3.3, if 3.3 final includes it - I don't think there's a workaround for it.

@smarter
Copy link
Member

smarter commented Jul 17, 2023

You can work around this by replacing val prefix: T = ... by val prefix: OuterTrait = ..., does that work for your usecase?

@neko-kai
Copy link
Contributor Author

neko-kai commented Jul 17, 2023

@smarter
Thanks for the suggestion! Unfortunately for me, the real macro was structured like this:

import scala.quoted.{Expr, Quotes, Type, quotes}

trait OuterTrait { self =>
  trait X
  
  def exampleMacro[T <: self.type: Type](expr: Expr[T])(using Quotes): Expr[self.X] = {
    '{
      val prefix: T = ${ expr }
      new prefix.X {}
    }
  }
}

because of self.X return type, T cannot be replaced by OuterTrait, it must be self.type.

But it appears that this bug was fixed already in 3.3.0, neither variant of the snippet causes an error anymore:

https://scastie.scala-lang.org/7Qn2ZOBlTyaoUIPWwboSCA
https://scastie.scala-lang.org/4uZfLU78Q0ehKI4WehMCEQ

I'm closing this, although it might be prudent to add a test for this to the test suite.

@neko-kai
Copy link
Contributor Author

neko-kai commented Jul 17, 2023

It was reintroduced again in 3.3.1-RC1+ and still present in 3.3.1-RC4 ...

https://scastie.scala-lang.org/KcD6pkn4RhWHewJaSRtmuA
https://scastie.scala-lang.org/B8PHfwyQRvmOpVVYyl2V7w

(I worked around the issue using smarter's suggestion & asInstanceOf)

@neko-kai neko-kai reopened this Jul 17, 2023
@Kordyjan
Copy link
Contributor

Kordyjan commented Jul 18, 2023

To be exact, 3.3.0 was branched out way before the commit that introduced the bug. Therefore, the bug is a regression introduced in 3.3.1.
It should be sorted out in 3.3.2.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2023
smarter added a commit that referenced this issue Jul 19, 2023
If the prefix of a `TypeRef` is a `TypeRef` we just `mapOver`.

Fixes #17293
@Kordyjan Kordyjan added the backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" label Jul 21, 2023
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
@Kordyjan Kordyjan removed the backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" label Aug 2, 2023
Kordyjan pushed a commit to dotty-staging/dotty that referenced this issue Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants