- Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
Compiler version
3.8.0-RC1-bin-20251001-28a4921-NIGHTLY
Latest nightly at the time of writing
Minimized code
shapeless.scala
package shapeless { sealed trait HList final case class ::[+H, +T <: HList](head: H, tail: T) extends HList sealed trait HNil extends HList case object HNil extends HNil trait Default[T] { type Out <: HList } object Default { type Aux[T, Out0 <: HList] = Default[T] {type Out = Out0} transparent inline given materialize[T]: Default[T] = ${ defaultImpl[T] } import scala.quoted.* def defaultImpl[T: Type](using quotes: Quotes): Expr[Default[T]] = { import quotes.reflect.* val tpe = TypeRepr.of[T] if (tpe <:< TypeRepr.of[test.CC]) '{ new Default[T] { type Out = None.type :: Some[String] :: Some[Option[Boolean]] :: HNil } } else quotes.reflect.report.errorAndAbort(s"No default implementation for ${tpe.show}") } } }
main.scala
//> using scala 3.8.0-RC1-bin-20251001-28a4921-NIGHTLY //> using option -Yretain-trees package test import shapeless.* case class CC(a: Int, b: String = "c", c: Option[Boolean] = Some(false)) val foo1: Default.Aux[CC, None.type :: Some[String] :: Some[Option[Boolean]] :: HNil] = summon[Default[CC]] // Does not compile val foo2: Default.Aux[CC, None.type :: Some[String] :: Some[Option[Boolean]] :: HNil] = summon[Default.Aux[CC, None.type :: Some[String] :: Some[Option[Boolean]] :: HNil]]
Output
[error] .\main.scala:11:172 [error] No given instance of type shapeless.Default.Aux[test.CC, None.type :: Some[String] :: [error] Some[Option[Boolean]] :: shapeless.HNil] was found for parameter x of method summon in object Predef [error] val foo2: Default.Aux[CC, None.type :: Some[String] :: Some[Option[Boolean]] :: HNil] = summon[Default.Aux[CC, None.type :: Some[String] :: Some[Option[Boolean]] :: HNil]] [error]
Expectation
It compiles. It seems like the compiler doesn't even try the macro, maybe because the type doesn't completely match up with what it expects.