diff --git a/modules/core/src/main/scala/com/github/tarao/record4s/Macros.scala b/modules/core/src/main/scala/com/github/tarao/record4s/Macros.scala index 5e6b0d4..b532ae2 100644 --- a/modules/core/src/main/scala/com/github/tarao/record4s/Macros.scala +++ b/modules/core/src/main/scala/com/github/tarao/record4s/Macros.scala @@ -222,13 +222,31 @@ object Macros { import quotes.reflect.* import internal.* - if (TypeRepr.of[T].dealias.typeSymbol.isTypeParam) - errorAndAbort( - Seq( - s"A concrete type expected but type variable ${Type.show[T]} is given.", - "Did you forget to make the method inline?", - ).mkString("\n"), + type Acc = List[Type[?]] + def freeTypeVariables[T: Type]: Acc = + traverse[T, Acc]( + List.empty, + (acc: Acc, tpe: Type[?]) => { + tpe match { + case '[t] if TypeRepr.of[t].typeSymbol.isTypeParam => + tpe :: acc + case _ => + acc + } + }, ) + + val vs = freeTypeVariables[T] + if (vs.nonEmpty) + vs.head match { + case '[tpe] => + errorAndAbort( + Seq( + s"A concrete type expected but type variable ${Type.show[tpe]} is given.", + "Did you forget to make the method inline?", + ).mkString("\n"), + ) + } else '{ Concrete diff --git a/modules/core/src/test/scala/com/github/tarao/record4s/TypeErrorSpec.scala b/modules/core/src/test/scala/com/github/tarao/record4s/TypeErrorSpec.scala index f7ecb15..424e410 100644 --- a/modules/core/src/test/scala/com/github/tarao/record4s/TypeErrorSpec.scala +++ b/modules/core/src/test/scala/com/github/tarao/record4s/TypeErrorSpec.scala @@ -64,6 +64,14 @@ class TypeErrorSpec extends helper.UnitSpec { typing.Record.Concat.Aux[R1, R2, RR], ): RR = r1 ++ r2 """)) + + trait A + + checkErrors(typeCheckErrors(""" + def concat[R1 <: %, R2 <: %, RR <: %](r1: R1, r2: R2 & Tag[A])(using + typing.Record.Concat.Aux[R1, R2 & Tag[A], RR], + ): RR = r1 ++ r2 + """)) } }