Skip to content

Commit

Permalink
Hotfix: fix a regression in 1.2.9 where ConfTags with similar paths w…
Browse files Browse the repository at this point in the history
…ere lost when module was included (#2136)
  • Loading branch information
neko-kai authored Jun 17, 2024
1 parent 171a28d commit 6384548
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import izumi.fundamentals.platform.cache.CachedProductHashcode

import scala.language.implicitConversions

/** An attachment that can be added to a binding using its `.tagged` method */
/** An attachment that can be added to a binding using its `.tagged` method
*
* @note an inheritor of BindingTag must be an immutable case class
* and all of its fields must be used in `equals` / `hashCode`.
*/
trait BindingTag extends CachedProductHashcode { this: Product => }

object BindingTag {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package izumi.distage.config

import com.github.pshirshov.configapp.SealedTrait.CaseClass2
import com.github.pshirshov.configapp.SealedTrait2.{No, Yes}
import com.github.pshirshov.configapp._
import com.typesafe.config._
import distage.Injector
import izumi.distage.config.model.AppConfig
import com.github.pshirshov.configapp.*
import com.typesafe.config.*
import distage.{Injector, Mode, Repo}
import izumi.distage.config.model.{AppConfig, ConfTag}
import izumi.distage.model.PlannerInput
import izumi.distage.model.definition.ModuleDef
import org.scalatest.wordspec.AnyWordSpec

import scala.collection.immutable.ListSet
Expand Down Expand Up @@ -163,6 +164,27 @@ final class ConfigTest extends AnyWordSpec {
assert(context2.get[Service[SealedCaseClass]].conf == SealedCaseClass(SealedTrait.CaseClass2(2, false, No)))
}

"regression test: same path ConfTags are preserved when processing includes" in {
final case class A()
final case class B()
final case class C()

val defn = new ModuleDef {
tag(Repo.Prod)

include(new ConfigModuleDef {
tag(Mode.Test)
makeConfig[A]("x")
makeConfig[B]("x")
makeConfig[C]("x")
})
}

val confTags = defn.bindings.toList.flatMap(_.tags.collect { case c: ConfTag => c })

assert(confTags.map(_.tpe).toSet.size == 3)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ object ConfigModuleDef {
final class FromConfig[T](private val make: MakeDSL[T]) extends AnyVal {
def fromConfig(path: String)(implicit tag: Tag[T], dec: DIConfigReader[T], meta: DIConfigMeta[T]): MakeDSLUnnamedAfterFrom[T] = {
val parser = wireConfig[T](path)
make.tagged(ConfTag(path)(parser, meta.tpe)).from(parser)
make.tagged(ConfTag(path, parser, meta.tpe)).from(parser)
}
def fromConfigNamed(path: String)(implicit tag: Tag[T], dec: DIConfigReader[T], meta: DIConfigMeta[T]): MakeDSLNamedAfterFrom[T] = {
val parser = wireConfig[T](path)
make.named(path).tagged(ConfTag(path)(parser, meta.tpe)).from(parser)
make.named(path).tagged(ConfTag(path, parser, meta.tpe)).from(parser)
}
def fromConfigWithDefault(path: String)(default: => T)(implicit tag: Tag[T], dec: DIConfigReader[T], meta: DIConfigMeta[T]): MakeDSLUnnamedAfterFrom[T] = {
val parser = wireConfigWithDefault[T](path)(default)
make.tagged(ConfTag(path)(parser, meta.tpe)).from(parser)
make.tagged(ConfTag(path, parser, meta.tpe)).from(parser)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import izumi.distage.config.codec.ConfigMetaType
import izumi.distage.model.definition.BindingTag

final case class ConfTag(
confPath: String
)(/* excluded from equals/hashCode */
val parser: AppConfig => Any,
val tpe: ConfigMetaType,
confPath: String,
parser: AppConfig => Any,
tpe: ConfigMetaType,
) extends BindingTag

0 comments on commit 6384548

Please sign in to comment.