scalalandio / chimney

Scala library for boilerplate-free, type-safe data transformations
https://chimney.readthedocs.io
Apache License 2.0
1.17k stars 94 forks source link

Provide Scala-version-agnostic way of reading macro settings #572

Closed MateuszKubuszok closed 3 months ago

MateuszKubuszok commented 3 months ago
codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 64.16667% with 86 lines in your changes missing coverage. Please review.

Project coverage is 86.73%. Comparing base (919f243) to head (53e9cda). Report is 86 commits behind head on master.

Files with missing lines Patch % Lines
...mney/internal/compiletime/ChimneyDefinitions.scala 4.34% 44 Missing :warning:
...letime/derivation/transformer/Configurations.scala 10.52% 17 Missing :warning:
...d/chimney/internal/compiletime/ExprsPlatform.scala 56.66% 13 Missing :warning:
...ternal/compiletime/derivation/GatewayCommons.scala 50.00% 5 Missing :warning:
...ompiletime/derivation/patcher/Configurations.scala 28.57% 5 Missing :warning:
...nal/compiletime/derivation/codec/CodecMacros.scala 93.33% 1 Missing :warning:
...nternal/compiletime/derivation/iso/IsoMacros.scala 93.33% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #572 +/- ## ========================================== - Coverage 88.05% 86.73% -1.33% ========================================== Files 153 154 +1 Lines 5911 5986 +75 Branches 500 540 +40 ========================================== - Hits 5205 5192 -13 - Misses 706 794 +88 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

MateuszKubuszok commented 3 months ago

I need to test somehow whether this change will not break https://github.com/scalalandio/chimney/issues/496 / https://github.com/scalalandio/chimney/pull/497. Testing it is a bit of a PITA, but the is nothing in the ADTs' API (both on Scala2 and on Scala 3) that would make me certain I used them the right way.

MateuszKubuszok commented 3 months ago

(sbt publish-local-for-tests)

Sooo:

//> using plugin org.wartremover:::wartremover:3.1.7
// Scala 2:
//> using scala 2.13.14
//> using options -Xfatal-warnings -P:wartremover:traverser:org.wartremover.warts.Unsafe -Wmacros:both -Xmacro-settings:chimney.SuppressWarnings=none -Vmacro
//> using dep io.scalaland::chimney:1.3.0-6-g42ce88f-SNAPSHOT

case class Foo(a: Option[String], b: Option[Int])
case class Bar(a: String, b: Int, c: Long)

import io.scalaland.chimney.dsl._

println(
scala.compiletime.codeOf(
Foo(Some("test"), Some(1024))
  .intoPartial[Bar]
  .withFieldConst(_.c, 1024L)
  .transform
)
)

always pass (even though @SuppressWarnings is disabled, and we can check with -Vmacro that it gets properly set up to be modified/left intact/removed) while

//> using plugin org.wartremover:::wartremover:3.1.7
// Scala 3:
//> using scala 3.3.3
//> using options -Xfatal-warnings -P:wartremover:traverser:org.wartremover.warts.Unsafe -Xmacro-settings:chimney.SuppressWarnings=org.wartremover.warts.Var
//> using dep io.scalaland::chimney:1.3.0-6-g42ce88f-SNAPSHOT

case class Foo(a: Option[String], b: Option[Int])
case class Bar(a: String, b: Int, c: Long)

import io.scalaland.chimney.dsl._

println(
Foo(Some("test"), Some(1024))
  .intoPartial[Bar]
  .withFieldConst(_.c, 1024L)
  .transform
)
)

always fails (an in the source code annotations are always absent :/)

MateuszKubuszok commented 3 months ago

After testing with sbt... Scala 2 works as expected... while Scala 3 always pass, whether annotations are applied or not :/

// build.sbt

libraryDependencies += "io.scalaland" %% "chimney" % "1.3.0-7-g939c063-SNAPSHOT"

wartremoverErrors ++= Warts.all

//scalaVersion := "3.3.3"
scalaVersion := "2.13.14"
scalacOptions += "-Wmacros:both" // Scala 2-only
scalacOptions += "-Xmacro-settings:chimney.SuppressWarnings=none"
scalacOptions += "-Xmacro-settings:chimney.transformer.MacrosLogging=true"
// project/plugins.sbt
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.7")
// src/main/scala/test/example.scala
package test

import io.scalaland.chimney.dsl._

final case class Foo(a: Option[String], b: Option[Int])
final case class Bar(a: String, b: Int, c: Long)

object Example {

  def main(args: Array[String]): Unit =
  println(
    Foo(Some("test"), Some(1024))
      .intoPartial[Bar]
      .withFieldConst(_.c, 1024L)
      //.enableMacrosLogging
      .transform
  )
}
MateuszKubuszok commented 3 months ago

Sooo, for now let's continue, it seems that behavior is unchanged (verified with newer commit and Scala 3), if we notice some changes in wartemover and Scala 3 we'll return to the this.