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

Hotfix: fix a regression in 1.2.9 where ConfTags with similar paths were lost when module was included #2136

Merged
merged 1 commit into from
Jun 17, 2024
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 @@ -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
Loading