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

Wrong value parsed when having a key that starts with the value of another key using hyphens #82

Open
fmeeuw opened this issue Aug 30, 2019 · 1 comment

Comments

@fmeeuw
Copy link

fmeeuw commented Aug 30, 2019

When having both foo-bar and foo present in a case class, Ficus attempts to parse the value of foo-bar and assign it to foo. When they both have different types this results in a ClassCastException, however when the types are the same, ficus will assign the value of foo-bar to both foo and foo-bar.

Example that fails with ClassCastException.

import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import com.typesafe.config._

case class TestSettings(val `foo-bar`: Long, `foo`: String)

val config = ConfigFactory.parseString("""{ foo-bar: 3, foo: "4" }""")
val settings = config.as[TestSettings] // throws java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String!

Example that doesn't fail, but assigns the value of foo-bar to foo.

case class TestSettings2(val `foo-bar`: String, `foo`: String)

val config = ConfigFactory.parseString("""{ foo-bar: "foo-bar", foo: "foo" }""")
val settings = config.as[TestSettings2]
println(settings.`foo-bar`) // prints out foo-bar
println(settings.foo) // also prints out foo-bar!
@fmeeuw
Copy link
Author

fmeeuw commented Sep 11, 2019

It seems to be a bug in the scala compiler: scala/bug#8831, as pointed out by @jcazevedo from pureconfig.

Philippus added a commit to Philippus/ficus that referenced this issue Feb 14, 2021
kailuowang pushed a commit that referenced this issue Jun 22, 2021
* Extend scala.annotation.Annotation

* Supply empty argument list explicitly

* Update scala 2.13.0 to 2.13.4

* Update sbt-scoverage to 1.6.1

* Add test for issue #82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant