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

Reference to quoted local member fails to in quote pickling #17103

Closed
nicolasstucki opened this issue Mar 15, 2023 · 2 comments · Fixed by #17107
Closed

Reference to quoted local member fails to in quote pickling #17103

nicolasstucki opened this issue Mar 15, 2023 · 2 comments · Fixed by #17107
Assignees
Milestone

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Mar 15, 2023

Compiler version

3.3.1-RC1-bin-20230313-f28d708-NIGHTLY and before

Minimized code

import scala.quoted.*

def test(using Quotes): Expr[Unit] =
  '{
    trait C:
      val d: Int
    val c: C = ???
    ${
      val expr = '{
        val cRef: c.type = ???
        cRef.d
        ()
      }
      expr
    }
  }

Output (click arrow to expand)

Exception in thread "main" 
  unhandled exception while running pickleQuotes on tests/neg-macros/path-dependent-type-capture.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/lampepfl/dotty/issues/new/choose

     while compiling: <no file>
        during phase: <no phase>
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.10
    compiler version: version 3.3.1-RC1-bin-SNAPSHOT-nonbootstrapped-git-29e229b
            settings: -Vprint List(splicing, staging) -classpath /Users/nicolasstucki/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar:/Users/nicolasstucki/Github/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.3.1-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.3.1-RC1-bin-SNAPSHOT.jar -d t/out -pagewidth 120

                tree: EmptyTree
       tree position: :<unknown>
           tree type: <notype>
              symbol: val <none>
           call site: package <root> in module class <root>

  == Source file context for tree position ==
java.lang.AssertionError: assertion failed: unresolved symbols: value cRef (line 11) #15683 when pickling tests/neg-macros/path-dependent-type-capture.scala
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:809)
        at dotty.tools.dotc.quoted.PickledQuotes$.pickle(PickledQuotes.scala:222)
        at dotty.tools.dotc.quoted.PickledQuotes$.pickleQuote(PickledQuotes.scala:34)
        at dotty.tools.dotc.transform.PickleQuotes$.pickleAsTasty$1(PickleQuotes.scala:291)
        ...
@nicolasstucki
Copy link
Contributor Author

This should not compile as it is impossible to pickle the selection of d in the inner quote.

@nicolasstucki
Copy link
Contributor Author

In theory, to make it work we would need to write a static interface on which we can select d.

trait C0:
  val d: Int
def test(using Quotes): Expr[Unit] =
  '{
    trait C extends C0:
      val d: Int
    val c: C = ???
    ${
      val expr = '{
        val cRef: c.type = ???
        cRef.d
        ()
      }
      expr
    }
  }

But this also fails with the same error. But it should work.

@nicolasstucki nicolasstucki self-assigned this Mar 15, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 15, 2023
If an inner quote selects a symbol that is defined in an outer quote we
need to transform it or reject it. The issue is that the inner quote
cannot contain a reference to the type of the class defined in the outer
quote. Any such reference is erased the parents of that class that are
statically know outside those quotes. If the selected symbol is
overriding a symbol in one of those statically known classes, we can use
that overridden symbol instead. If not we have to reject the code.

Fixes scala#17103
nicolasstucki added a commit that referenced this issue Mar 21, 2023
If an inner quote selects a symbol that is defined in an outer quote we
need to transform it or reject it. The issue is that the inner quote
cannot contain a reference to the type of the class defined in the outer
quote. Any such reference is erased the parents of that class that are
statically know outside those quotes. If the selected symbol is
overriding a symbol in one of those statically known classes, we can use
that overridden symbol instead. If not we have to reject the code.

Fixes #17103
Dedelweiss pushed a commit to Dedelweiss/dotty that referenced this issue Apr 17, 2023
If an inner quote selects a symbol that is defined in an outer quote we
need to transform it or reject it. The issue is that the inner quote
cannot contain a reference to the type of the class defined in the outer
quote. Any such reference is erased the parents of that class that are
statically know outside those quotes. If the selected symbol is
overriding a symbol in one of those statically known classes, we can use
that overridden symbol instead. If not we have to reject the code.

Fixes scala#17103
@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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants