diff --git a/guinep/src/main/scala/macros.scala b/guinep/src/main/scala/macros.scala index c4df3c5..6127ce5 100644 --- a/guinep/src/main/scala/macros.scala +++ b/guinep/src/main/scala/macros.scala @@ -39,6 +39,12 @@ private[guinep] object macros { private def prettyName: String = s.name.stripSuffix("$") + extension (tpe: TypeRepr) + private def stripAnnots: TypeRepr = tpe match { + case AnnotatedType(tpe, _) => tpe.stripAnnots + case _ => tpe + } + private def functionNameImpl(f: Expr[Any]): Expr[String] = { val name = f.asTerm match { case Inlined(_, _, Lambda(_, body)) => @@ -100,13 +106,13 @@ private[guinep] object macros { fields.map { valdef => functionFormElementFromTree( valdef.name, - valdef.tpt.tpe.substituteTypes(typeDefParams, ntpe.typeArgs) + valdef.tpt.tpe.substituteTypes(typeDefParams, ntpe.typeArgs).stripAnnots ) } ) case ntpe if isSumTpe(ntpe) => val classSymbol = ntpe.typeSymbol - val childrenAppliedTpes = classSymbol.children.map(child => appliedChild(child, classSymbol, ntpe.typeArgs)) + val childrenAppliedTpes = classSymbol.children.map(child => appliedChild(child, classSymbol, ntpe.typeArgs)).map(_.stripAnnots) val childrenFormElements = childrenAppliedTpes.map(t => functionFormElementFromTree("value", t)) val options = classSymbol.children.map(_.prettyName).zip(childrenFormElements) FormElement.Dropdown(paramName, options) @@ -170,7 +176,7 @@ private[guinep] object macros { val classSymbol = ntpe.typeSymbol val className = classSymbol.name val children = classSymbol.children - val childrenAppliedTpes = children.map(child => appliedChild(child, classSymbol, ntpe.typeArgs)) + val childrenAppliedTpes = children.map(child => appliedChild(child, classSymbol, ntpe.typeArgs)).map(_.stripAnnots) val paramMap = '{ ${param.asExpr}.asInstanceOf[Map[String, Any]] }.asTerm val paramName = paramMap.select("apply").appliedTo(Literal(StringConstant("name"))) val paramValue = paramMap.select("apply").appliedTo(Literal(StringConstant("value"))) diff --git a/testcases/src/main/scala/main.scala b/testcases/src/main/scala/main.scala index b3ddf44..b884e37 100644 --- a/testcases/src/main/scala/main.scala +++ b/testcases/src/main/scala/main.scala @@ -62,10 +62,15 @@ case class IntValue(value: Int) extends WeirdGADT[Int] case class SomeValue[+A](value: A) extends WeirdGADT[A] case class SomeOtherValue[+A, +B](value: A, value2: B) extends WeirdGADT[A] +// This fails on unknown type params def printsWeirdGADT(g: WeirdGADT[String]): String = g match case SomeValue(value) => s"SomeValue($value)" case SomeOtherValue(value, value2) => s"SomeOtherValue($value, $value2)" +// This loops forever +def concatAll(elems: List[String]): String = + elems.mkString + @main def run: Unit = guinep.web( @@ -82,4 +87,5 @@ def run: Unit = roll20, roll6(), // printsWeirdGADT + // concatAll )