7mind / izumi

Productivity-oriented collection of lightweight fancy stuff for Scala toolchain
https://izumi.7mind.io
BSD 2-Clause "Simplified" License
615 stars 66 forks source link

cglib Auto-Traits fail on AnyVals #452

Closed neko-kai closed 4 years ago

neko-kai commented 5 years ago

This test fails:

  "progression test: can't handle AnyVals" in {
    import TraitCase6._

    val definition = new ModuleDef {
      make[Dep]
      make[AnyValDep].from(AnyValDep(_))
      make[TestTrait]
    }

    val injector = mkInjector()
    val plan = injector.plan(definition)
    val context = injector.produce(plan)

    assert(context.get[TestTrait].anyValDep != null)

    // AnyVal reboxing happened
    assert(context.get[TestTrait].anyValDep ne context.get[AnyValDep].asInstanceOf[AnyRef])
    assert(context.get[TestTrait].anyValDep.d eq context.get[Dep])
  }

On the != null assertion with:

class com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$AnyValDep cannot be cast to class com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$Dep (com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$AnyValDep and com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$Dep are in unnamed module of loader 'app')
java.lang.ClassCastException: class com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$AnyValDep cannot be cast to class com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$Dep (com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$AnyValDep and com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$Dep are in unnamed module of loader 'app')
    at com.github.pshirshov.izumi.distage.fixtures.TraitCases$TraitCase6$TestTrait$$EnhancerByCGLIB$$ceccd269.anyValDep(<generated>)
    at com.github.pshirshov.izumi.distage.injector.AutoTraitsTest.$anonfun$new$11(AutoTraitsTest.scala:145)

The same test for distage-static macro auto-traits passes.

Fix: use the same AnyVal unboxing logic in CgLibTraitMethodInterceptor.intercept from ClassStrategyDefaultImpl

neko-kai commented 4 years ago

Fixed in #741