Skip to content

Type annotation lost in tuple type decomposition #22777

Open
@prolativ

Description

@prolativ

Compiler version

3.3.5, 3.6.4, 3.7.0-RC1-bin-20250309-2f639e2-NIGHTLY

Minimized code

Lib.scala:

import scala.quoted.*

class myAnnot extends scala.annotation.StaticAnnotation

inline def showType[A]: String = ${ showTypeImpl[A] }

def showTypeImpl[A : Type](using Quotes): Expr[String] =
  Expr(Type.show[A])

inline def showHeadType[T <: Tuple]: Option[String] = ${ showHeadTypeImpl[T] }

def showHeadTypeImpl[A : Type](using Quotes): Expr[Option[String]] =
  Type.of[A] match
    case '[head *: tail] =>
      Expr(Some(Type.show[head]))
    case _ =>
      Expr(None)

Test.scala:

@main def run() =
  println(showType[EmptyTuple])
  println(showHeadType[EmptyTuple])
  println(showType[Tuple1[Int]])
  println(showHeadType[Tuple1[Int]])
  println(showType[Tuple.Head[Tuple1[Int]]])
  println(showType[Tuple1[Int @myAnnot]])
  println(showHeadType[Tuple1[Int @myAnnot]])
  println(showType[Tuple.Head[Tuple1[Int @myAnnot]]])

Output (scala 3.6.4, 3.7.0-RC1-bin-20250309-2f639e2-NIGHTLY):

scala.Tuple$package.EmptyTuple
None
scala.Tuple1[scala.Int]
Some(scala.Int)
scala.Int
scala.Tuple1[scala.Int @myAnnot]
Some(scala.Int)
scala.Int @myAnnot

Output (scala 3.3.5):

scala.Tuple$package.EmptyTuple
None
scala.Tuple1[scala.Int]
Some(scala.Int)
scala.Int
scala.Tuple1[scala.Int @myAnnot]
Some(scala.Int)
scala.Int @myAnnot

Expectation

scala.Tuple$package.EmptyTuple
None
scala.Tuple1[scala.Int]
Some(scala.Int)
scala.Int
scala.Tuple1[scala.Int @myAnnot]
Some(scala.Int @myAnnot)
scala.Int @myAnnot

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions