Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix allPartsStrong #279

Merged
merged 3 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class TagMacro(using override val qctx: Quotes) extends InspectorBase {
override def shift: Int = 0

def createTagExpr[A <: AnyKind: Type]: Expr[Tag[A]] = {
val typeRepr = TypeRepr.of[A]
val typeRepr = TypeRepr.of[A].dealias
if (allPartsStrong(typeRepr)) {
// NB: this should always work, but currently causes `TestModel$::ApplePaymentProvider is not a type lambda, it cannot be parameterized` test failure
// There's probably a missing case where a higher-kinded type is not a type lambda, with splicing inbetween causing fixup by the compiler
Expand All @@ -41,6 +41,7 @@ final class TagMacro(using override val qctx: Quotes) extends InspectorBase {

private def summonCombinedTag[T <: AnyKind: Type](typeRepr: TypeRepr): Expr[Tag[T]] =
typeRepr.dealias match {
case x @ TypeRef(ThisType(_), _) if x.typeSymbol.isAbstractType && !x.typeSymbol.isClassDef => summonTag(x)

case x if x.typeSymbol.isTypeParam => summonTag(x)

Expand Down Expand Up @@ -82,6 +83,7 @@ final class TagMacro(using override val qctx: Quotes) extends InspectorBase {
private def allPartsStrong(typeRepr: TypeRepr): Boolean =
typeRepr.dealias match {
case x if x.typeSymbol.isTypeParam => false
case x @ TypeRef(ThisType(_), _) if x.typeSymbol.isAbstractType && !x.typeSymbol.isClassDef => false
case AppliedType(tpe, args) => allPartsStrong(tpe) && args.forall(allPartsStrong)
case AndType(lhs, rhs) => allPartsStrong(lhs) && allPartsStrong(rhs)
case OrType(lhs, rhs) => allPartsStrong(lhs) && allPartsStrong(rhs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ trait T2[A, B, C[_[_], _], D[_], E]

abstract class SharedTagTest extends AnyWordSpec with XY[String] with TagAssertions with InheritedModelKindProjector {

type Abstract
type Swap[A, B] = Either[B, A]
type SwapF2[F[_, _], A, B] = F[B, A]
type Id[A] = A
Expand Down Expand Up @@ -302,4 +303,31 @@ abstract class SharedTagTest extends AnyWordSpec with XY[String] with TagAsserti

}

"Does not synthesize Tags for abstract types, but recursively summons (this.Abstract)" in {
implicit val tag0: Tag[Abstract] = Tag.apply(Tag[Int].closestClass, Tag[Int].tag)
val tag = Tag[Option[Abstract]]
assert(tag.tag.typeArgs.head == tag0.tag)
}

"DOES synthesize Tags for abstract types (object X; X.T)" in {
implicit val tag0: Tag[SomeObject.Abstract] = Tag.apply(Tag[Int].closestClass, Tag[Int].tag)
val tag = Tag[Option[SomeObject.Abstract]]
assert(tag.tag.typeArgs.head != tag0.tag)
}

"DOES synthesize Tags for abstract types (trait X; X#T)" in {
implicit val tag0: Tag[SomeTrait#Abstract] = Tag.apply(Tag[Int].closestClass, Tag[Int].tag)
val tag = Tag[Option[SomeTrait#Abstract]]
assert(tag.tag.typeArgs.head != tag0.tag)
}

}


trait SomeTrait {
type Abstract
}

object SomeObject {
type Abstract
}