Skip to content

Detect explicitly spliced wildcard types #8871

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 May 4, 2020 · 1 comment · Fixed by #8872
Closed

Detect explicitly spliced wildcard types #8871

nicolasstucki opened this issue May 4, 2020 · 1 comment · Fixed by #8872

Comments

@nicolasstucki
Copy link
Contributor

We are not allowed to splice wildcard types to avoid soundness issues. They are not checked when explicitly spliced:

import scala.quoted._
object Macro {
  def impl[A : Type](using qctx: QuoteContext): Unit = {
    import qctx.tasty._
    val tpe = typeOf[A].seal.asInstanceOf[quoted.Type[_ <: AnyRef]]
    '{ (a: ${tpe}) => ???} // should be an error
  }
}
import scala.quoted._
object Macro {
  def impl[A : Type](using qctx: QuoteContext): Unit = {
    import qctx.tasty._
    val tpe/*: quoted.Type[? <: AnyKind]*/ = typeOf[A].seal
    '{ f[$tpe] } // should be an error
  }
  def f[T <: AnyKind]: Unit = ()
}
@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented May 4, 2020

See #8865 (comment)

The way to make this work is by creating an existential type X for the type such that tpe is typed as quoted.Type[X]

We have logic in the compiler to do this sort of things automatically for wildcard types it's called skolemization, maybe this could be extended to deal with quotes: https://github.com/lampepfl/dotty/blob/5d6d6aa3797d000800d68f027574aeaee47aa3c2/compiler/src/dotty/tools/dotc/typer/Typer.scala#L3211-L3216

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 5, 2020
nicolasstucki added a commit that referenced this issue May 6, 2020
Fix #8871: Detect explicit splices of quoted.Type[?]
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.

1 participant