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

"Could not find proxy for implicit evidence" when using doubly nested quotes #17026

Closed
kitlangton opened this issue Feb 28, 2023 · 3 comments · Fixed by #17051
Closed

"Could not find proxy for implicit evidence" when using doubly nested quotes #17026

kitlangton opened this issue Feb 28, 2023 · 3 comments · Fixed by #17051
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Milestone

Comments

@kitlangton
Copy link

Compiler version

3.2.2

Minimized code

import scala.quoted.*

def macroImpl(using Quotes) =
  '{
    def weird[A: ToExpr: Type](a: A)(using quotes: Quotes) =
      '{ Some(${ Expr(a) }) }
  }

Output

[error] (Test / compileIncremental) java.lang.IllegalArgumentException: Could not find proxy for implicit evidence$2: scala.quoted.Type in [parameter evidence$2, method weird, method macroImpl, package object Reproducer$package, package quotidian, package <root>], encl = method macroImpl, owners = method macroImpl, package object Reproducer$package, package quotidian, package <root>; enclosures = method macroImpl, package object Reproducer$package, package quotidian, package <root>

Expectation

Well, it'd be great if it somehow compiled 😄
I'm certainly doing some weird stuff, what with the doubly nested quotes and all. For context, I wrote some macros for deriving ToExpr and FromExpr (https://github.com/kitlangton/quotidian). However, they don't work with parameterized types.

@kitlangton kitlangton added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 28, 2023
@szymon-rd
Copy link
Contributor

Thank you for reporting!

@szymon-rd szymon-rd added area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 1, 2023
@nicolasstucki
Copy link
Contributor

Minimized

import scala.quoted.*
def macroImpl(using Quotes) = 
  '{ def weird[A: Type](using Quotes) = Type.of[A] }

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Mar 6, 2023

The issue is that in the staging phase we generate @SplicedType type evidence$1$_$1, which should only be generated for Type[T] that comes from outside the quote.

The solution is not to create evidence$1$_$1 and use evidence$1.Underlying directly.

[[syntax trees at end of                   staging]]
package <empty> {
  import scala.quoted.*
  final lazy module val Macro_1$package: Macro_1$package = new Macro_1$package()
  @SourceFile("t/Macro_1.scala") final module class Macro_1$package() extends
    Object() { this: Macro_1$package.type =>
    private def writeReplace(): AnyRef =
      new scala.runtime.ModuleSerializationProxy(classOf[Macro_1$package.type])
    def macroImpl(using x$1: quoted.Quotes): quoted.Expr[Unit] =
      '{
        {
          @SplicedType type evidence$1$_$1 = evidence$1.Underlying
          {
            def weird[A >: Nothing <: Any](implicit evidence$1: quoted.Type[A],
              x$1: quoted.Quotes): quoted.Type[A] =
              quoted.Type.of[evidence$1$_$1](x$1)
            ()
          }
        }
      }.apply(x$1)
  }
}

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 6, 2023
The type declarations annotated with `@SplicedType` are only meant for
types that come from outside the quote. If the reference to the `Type[T]`
is to a definition within the quote (i.e. its level is grater than 0) we
can use it directly. The `@SplicedType` for that type will be generated
in a future compilation phase when the `Type[T]` definition reaches
level 0.

Fixes scala#17026
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2023
The type declarations annotated with `@SplicedType` are only meant for
types that come from outside the quote. If the reference to the `Type[T]`
is to a definition within the quote (i.e. its level is grater than 0) we
can use it directly. The `@SplicedType` for that type will be generated
in a future compilation phase when the `Type[T]` definition reaches
level 0.

Fixes scala#17026
nicolasstucki added a commit that referenced this issue Mar 15, 2023
The type declarations annotated with `@SplicedType` are only meant for
types that come from outside the quote. If the reference to the
`Type[T]` is to a definition within the quote (i.e. its level is grater
than 0) we can use it directly. The `@SplicedType` for that type will be
generated in a future compilation phase when the `Type[T]` definition
reaches level 0.

Fixes #17026
Dedelweiss pushed a commit to Dedelweiss/dotty that referenced this issue Apr 17, 2023
The type declarations annotated with `@SplicedType` are only meant for
types that come from outside the quote. If the reference to the `Type[T]`
is to a definition within the quote (i.e. its level is grater than 0) we
can use it directly. The `@SplicedType` for that type will be generated
in a future compilation phase when the `Type[T]` definition reaches
level 0.

Fixes scala#17026
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants