Skip to content

Support type references to types within quotes #7405

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

Closed
nicolasstucki opened this issue Oct 11, 2019 · 1 comment
Closed

Support type references to types within quotes #7405

nicolasstucki opened this issue Oct 11, 2019 · 1 comment

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Oct 11, 2019

minimized code

import scala.quoted._
class Foo {
  def f(given QuoteContext): Expr[Any] = {
    '{
      type X = Int // Level 1
      // val x: X = ???
      ${
        val t: Type[X] = '[X] // Level 0
        '{ /*val y: $t = x*/ } 
      }
    }
  }
}

fails with

9 |        val t: Type[X] = '[X] // Level 0
  |                    ^
  |        access to type X from wrong staging level:
  |         - the definition is at level 1,
  |         - but the access is at level 0.
  |        
  |         The access would be accepted with an implict scala.quoted.Type[X]

expectation

This code should work.

To be able to have references to type tags of types defined in a higher level we need to generalize the concept of type healing. In this case we instead of needing to keep a type tag for the next stage it should be possible to refer to types for a next level. This is already the case inside of top level splices in inline methods (macros) but it should be possible to do in any code.

To make this change we will need to:

  • Adapt the PCP check to not complain for types if the definition is in a higher level than the use site.
  • Adapt types that may not be in scope after ReifyQuotes. This could be in PCPChecks or ReifyQuotes.
@nicolasstucki
Copy link
Contributor Author

This should also work for path dependent types.

import scala.quoted._

class Foo {
  def f(given QuoteContext): Expr[Any] = {
    '{
      trait X {
        type Y
        def y: Y = ???
      }
      val x: X = ???
      ${
        val t: Type[x.Y] = summon[Type[x.Y]]
        '{ val y: $t = x.y }
      }
    }
  }
}

@nicolasstucki nicolasstucki self-assigned this Nov 4, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 4, 2019
To be able to have references to type tags of types defined in a higher level we need to generalize the concept of type healing. In this case we instead of needing to keep a type tag for the next stage it should be possible to refer to types for a next level. This is already the case inside of top level splices in inline methods (macros) but it should be possible to do in any code.
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 4, 2019
To be able to have references to type tags of types defined in a higher level we need to generalize the concept of type healing. In this case we instead of needing to keep a type tag for the next stage it should be possible to refer to types for a next level. This is already the case inside of top level splices in inline methods (macros) but it should be possible to do in any code.
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 5, 2019
To be able to have references to type tags of types defined in a higher level we need to generalize the concept of type healing. In this case we instead of needing to keep a type tag for the next stage it should be possible to refer to types for a next level. This is already the case inside of top level splices in inline methods (macros) but it should be possible to do in any code.
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 16, 2019
To be able to have references to type tags of types defined in a higher level we need to generalize the concept of type healing. In this case we instead of needing to keep a type tag for the next stage it should be possible to refer to types for a next level. This is already the case inside of top level splices in inline methods (macros) but it should be possible to do in any code.
odersky added a commit that referenced this issue Jan 20, 2020
Fix #7405 and #7887: Allow types references at a lower level
OlivierBlanvillain pushed a commit to dotty-staging/dotty that referenced this issue Jan 23, 2020
To be able to have references to type tags of types defined in a higher level we need to generalize the concept of type healing. In this case we instead of needing to keep a type tag for the next stage it should be possible to refer to types for a next level. This is already the case inside of top level splices in inline methods (macros) but it should be possible to do in any code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant