Skip to content

Commit

Permalink
Merge pull request #19 from kasiaMarek/fix-generic-args
Browse files Browse the repository at this point in the history
fix: generic args in tyre `And`
  • Loading branch information
susuro authored Jul 22, 2024
2 parents 1fb074c + ece71ce commit 6778023
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/scala/net/marek/tyre/pattern/StringInterpolator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ private def tyreImpl(sc: Expr[StringContext], args: Expr[Seq[Any]])(using Quotes

import quotes.reflect.*

def isNETuple(tpe: TypeRepr): Boolean =
val tupleSymbol = Symbol.requiredClass("scala.NonEmptyTuple")
tpe <:< tupleSymbol.typeRef

val parts: Seq[String] = sc match
case '{ StringContext($t: _*) } =>
t match
Expand Down Expand Up @@ -54,8 +58,11 @@ private def tyreImpl(sc: Expr[StringContext], args: Expr[Seq[Any]])(using Quotes
toTyre(re1) match
case '{ $ree1: Tyre[t1] } =>
toTyre(re2) match
case '{ $ree2: Tyre[t2 *: t3] } => '{ AndF(${ ree1 }, ${ ree2 }) }
case '{ $ree2: Tyre[t2] } => '{ And(${ ree1 }, ${ ree2 }) }
case '{ $ree2: Tyre[t2] } =>
'{ ${ ree2 }.asInstanceOf[Tyre[t2]] } match
case '{ $ree2: Tyre[t2 *: t3] } if isNETuple(ree2.asTerm.tpe.widen.dealias.typeArgs.head) =>
'{ AndF(${ ree1 }, ${ ree2 }) }
case '{ $ree2: Tyre[t2] } => '{ And(${ ree1 }, ${ ree2 }) }
case ReOr(re1, re2) =>
toTyre(re1) match
case '{ $ree1: Tyre[t1] } =>
Expand Down
4 changes: 4 additions & 0 deletions src/test/scala/net/marek/tyre/StringInterpolatorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ class StringInterpolatorTest extends AnyFunSuite:
assertResult(Some(Some('a')))(m.run("a"))
assertResult(Some(None))(m.run(""))
assertResult(None)(m.run("aa"))

test("generic"):
val _ = [T, B] => (aa : Tyre[T], bb: Tyre[B]) => tyre"$aa$bb"
val _ = [T, B] => (aa : Conv[Int *: EmptyTuple, T], bb: Tyre[B]) => tyre"$bb$aa"

0 comments on commit 6778023

Please sign in to comment.