scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.72k stars 1.04k forks source link

Compiler crash when referencing type in quotes #18125

Closed WojciechMazur closed 11 months ago

WojciechMazur commented 1 year ago

Compiler version

Regression found in the Open Community Build in:

Compiler version

3.3.2-RC1-bin-20230629-90c59bd-NIGHTLY Bisect points to b7b13e5c8ffa110ea3fbc5667b636e7132850fdf

If you're not sure what version you're using, run print scalaVersion from sbt (if you're running scalac manually, use scalac -version instead).

Minimized code

//> using scala 3.nightly

package oolong.phobos

import scala.quoted.*
import scala.compiletime.*
import scala.annotation.StaticAnnotation

final class xmlns[T](ns: T) extends StaticAnnotation
trait Namespace[T]{
    val getNamespace: String
}

object common{
  private def extractFeildNamespace(using Quotes)(
      fieldAnnotations: List[Expr[Any]],
  ): Expr[Option[String]] = {
    import quotes.reflect.*

    fieldAnnotations.collect { case '{ xmlns($namespace: b) } =>
      '{ Some(summonInline[Namespace[b]].getNamespace) }
    }
    ???
  }
}

Output (click arrow to expand)

```scala //> using scala 3.nightly package oolong.phobos import scala.quoted.* import scala.compiletime.* import scala.annotation.StaticAnnotation final class xmlns[T](ns: T) extends StaticAnnotation trait Namespace[T]{ val getNamespace: String } object common{ private def extractFeildNamespace(using Quotes)( fieldAnnotations: List[Expr[Any]], ): Expr[Option[String]] = { import quotes.reflect.* fieldAnnotations.collect { case '{ xmlns($namespace: b) } => '{ Some(summonInline[Namespace[b]].getNamespace) } } ??? } } ```
nicolasstucki commented 1 year ago

Workaround

-    fieldAnnotations.collect { case '{ xmlns($namespace: b) } =>
+    fieldAnnotations.collect { case '{ xmlns[b]($namespace: b) } =>
nicolasstucki commented 1 year ago

Minimization

import scala.quoted.*

final class Foo[T](ns: T)

def foo(using Quotes)(x: Expr[Any]): Unit =
  x match
    case '{ new Foo($y: b) } =>