Skip to content

RuntimeAPI.unpack for abstract type bounds is broken since 3.0.4 (scala 2.13) #571

Description

@road21

Minimized example:

//> using scala 2.13
//> using dep "dev.zio::izumi-reflect:3.0.9"

import izumi.reflect.macrortti.LightTypeTagRef
import izumi.reflect.{Tag, TagK}
import izumi.reflect.macrortti.RuntimeAPI

trait X

type SomeType[S] <: S with X

trait RootTrait[P]
trait TestTrait[F[_]] extends RootTrait[SomeType[String]]

def foo[F[_]: TagK] =
  RuntimeAPI
    .unpack(implicitly[Tag[TestTrait[F]]].tag.ref match {
      case reference: LightTypeTagRef.AbstractReference => reference
    })

type Id[x] = x

println(foo[Id])

Output:

Exception in thread "main" java.lang.IllegalStateException: Expected applied reference but got λ %0  0 while processing {context::X & 0}
        at izumi.reflect.macrortti.RuntimeAPI$Rewriter.ensureApplied(RuntimeAPI.scala:203)
        at izumi.reflect.macrortti.RuntimeAPI$Rewriter.$anonfun$replaceApplied$2(RuntimeAPI.scala:135)

I understand that RuntimeAPI.unpack is low level method, but in this case this error leads to the following problem when using distage + estatico newtypes (or other newtypes with abstract type bounds of intersection types):

//> using scala 2.13
//> using dep "io.7mind.izumi::distage-core:1.2.20"

import distage.{Injector, ModuleDef, TagK}
import izumi.distage.model.plan.Roots

object Test {
  trait X

  type SomeType[S] <: S with X

  trait RootTrait[P]
  trait TestTrait[F[_]] extends RootTrait[SomeType[String]]

  object SomeModule {

    def apply[F[_]: TagK]: ModuleDef = new ModuleDef {
      make[TestTrait[F]].from { () => ??? }
    }
  }
}

type Id[x] = x

final class App

val injector: Injector[Id] = Injector[Id]()

val plan =
  injector
    .plan(Test.SomeModule.apply[Id], Roots.target[App])
    .getOrThrow()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions