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

workaround for a possible scala bug in show for value class. #1804

Merged
merged 5 commits into from
Aug 11, 2017

Conversation

kailuowang
Copy link
Contributor

fixes #1802

@codecov-io
Copy link

codecov-io commented Aug 9, 2017

Codecov Report

Merging #1804 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1804      +/-   ##
==========================================
+ Coverage   94.88%   94.88%   +<.01%     
==========================================
  Files         241      241              
  Lines        4147     4148       +1     
  Branches      107       97      -10     
==========================================
+ Hits         3935     3936       +1     
  Misses        212      212
Impacted Files Coverage Δ
core/src/main/scala/cats/Show.scala 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8bc6354...e07aa6b. Read the comment docs.

Copy link
Contributor

@edmundnoble edmundnoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks alright to me. I might consider naming it cshow because it's not really private - user-defined functions that require a ContravariantShow will need it, not sure if anyone will use that though.

@dwijnand
Copy link
Contributor

dwijnand commented Aug 9, 2017

Minimised and reported upstream at scala/bug#10458, if you want to leave a reference in the code.

@kailuowang
Copy link
Contributor Author

Thanks very much! @dwijnand

@kailuowang
Copy link
Contributor Author

Now I run into https://issues.scala-lang.org/browse/SI-6260 which is not fixed on 2.10.6
@dwijnand any suggestions?

@dwijnand
Copy link
Contributor

dwijnand commented Aug 9, 2017

Drop 2.10 support? :trollface:

Otherwise I suggest seeing if simulacrum can be taught to see the show inherited from ContravariantShow.

@@ -13,11 +13,12 @@ import cats.functor.Contravariant
@typeclass trait Show[T] extends Show.ContravariantShow[T] {
// duplicated so simulacrum knows it requires an instance of this trait
def show(t: T): String
def _show(t: T): String = show(t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be final?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved away from this solution.

@kailuowang
Copy link
Contributor Author

I can't get simulacrum to recoganize the super class. So i decided to hand roll the type class boilerplate by simulacrum


/**
* Hand rolling the type class boilerplate due to https://issues.scala-lang.org/browse/SI-6260 and scala/bug#10458
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SI-6260 is scala/bug#6260

@kailuowang
Copy link
Contributor Author

kailuowang commented Aug 9, 2017

so I got rid of the simulacrum and thus the duplicated show in Show, but I still can't get around SI-6260 in scala 2.10. I only see 2 options going forward

  1. leave everything as is, i.e. close this PR. The work around isn't that terrible, instead of creating the anonymous class instance of Show, use Show.show
  2. use the current fix, but give up on 2.10, which means I probably need to remove the regression test to get build passing.

What do you guys think? @johnynek @julien-truffaut @sellout @edmundnoble @dwijnand

@dwijnand
Copy link
Contributor

  1. use the current fix, but restrict the test to 2.11+ to avoid SI-6260.

@kailuowang
Copy link
Contributor Author

@dwijnand what would be the best way to restrict the test to 2.11+? I can think of using sbt-buildinfo to make scala version available in test code. Is there any other better ways?

@dwijnand
Copy link
Contributor

dwijnand commented Aug 10, 2017

unmanagedSourceDirectories in Test ++= {
  val ss = (scalaSource in Test).value
  if (CrossVersion.partialVersion(scalaVersion.value) exists (_._2 >= 11))
    Seq(file(ss.getPath + "-2.11+"))
  else
    Nil
}
> show crossScalaVersions
[info] * 2.10.6
[info] * 2.11.11
[info] * 2.12.3

> +show test:unmanagedSourceDirectories
[info] Setting version to 2.10.6
[info] * /s/t-test211/src/test/scala-2.10
[info] * /s/t-test211/src/test/scala
[info] * /s/t-test211/src/test/java

[info] Setting version to 2.11.11
[info] * /s/t-test211/src/test/scala-2.11
[info] * /s/t-test211/src/test/scala
[info] * /s/t-test211/src/test/java
[info] * /s/t-test211/src/test/scala-2.11+

[info] Setting version to 2.12.3
[info] * /s/t-test211/src/test/scala-2.12
[info] * /s/t-test211/src/test/scala
[info] * /s/t-test211/src/test/java
[info] * /s/t-test211/src/test/scala-2.11+

@kailuowang
Copy link
Contributor Author

thanks @dwijnand in scalajs enabled projects the scalaSource is
.jvm/src/test/scala, which means that the settings you gave added /cats/tests/.jvm/src/test/scala-2.11+ instead of
/cats/tests/src/test/scala-2.11+. I am not sure if this test should be jvm specific.
I wonder if there is a key pointing to /cats/tests/src/test/scala to use instead of scalaSource?

@dwijnand
Copy link
Contributor

Hmm, that makes things more complicated :)

unmanagedSourceDirectories in Test ++= {
  val bd = baseDirectory.value
  if (CrossVersion.partialVersion(scalaVersion.value) exists (_._2 >= 11))
    CrossType.Pure.sharedSrcDir(bd, "test").toList map (f => file(f.getPath + "-2.11+"))
  else
    Nil
}
> show tJVM/test:unmanagedSourceDirectories
[info] * /s/t-test211/.jvm/src/test/scala-2.12
[info] * /s/t-test211/.jvm/src/test/scala
[info] * /s/t-test211/.jvm/src/test/java
[info] * /s/t-test211/src/test/scala-2.12
[info] * /s/t-test211/src/test/scala
[info] * /s/t-test211/src/test/scala-2.11+

> show tJS/test:unmanagedSourceDirectories
[info] * /s/t-test211/.js/src/test/scala-2.12
[info] * /s/t-test211/.js/src/test/scala
[info] * /s/t-test211/.js/src/test/java
[info] * /s/t-test211/src/test/scala-2.12
[info] * /s/t-test211/src/test/scala
[info] * /s/t-test211/src/test/scala-2.11+

@kailuowang
Copy link
Contributor Author

Thanks! @dwijnand it would've taken me weeks to figure out. fix pushed.

@edmundnoble
Copy link
Contributor

Does this mean that 2.10 users won't be able to use Show?

@kailuowang
Copy link
Contributor Author

kailuowang commented Aug 10, 2017

@edmundnoble , it means that they will use Show.show when writing a Show instance for a value class.
And that's mostly due to scala/bug#6260 than anything else.

@kailuowang kailuowang merged commit 41402a8 into typelevel:master Aug 11, 2017
@kailuowang kailuowang deleted the fix-show branch August 11, 2017 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

java.lang.ClassFormatError: Duplicate method name&signature when upgrading to cats 1.0.0-MF
6 participants