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

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

Merged
merged 7 commits into from
Jul 17, 2024

Conversation

MateuszKubuszok
Copy link
Member

@MateuszKubuszok MateuszKubuszok commented Jul 14, 2024

  • Scala-version-agnostic -Xmacro-settings
  • allow overriding every single Transformer (Boolean) flag
    • chimney.transformer.InheritedAccessors=boolean
    • chimney.transformer.MethodAccessors=boolean
    • chimney.transformer.DefaultValues=boolean
    • chimney.transformer.BeanSetters=boolean
    • chimney.transformer.BeanSettersIgnoreUnmatched=boolean
    • chimney.transformer.NonUnitBeanSetters=boolean
    • chimney.transformer.BeanGetters=boolean
    • chimney.transformer.OptionDefaultsToNone=boolean
    • chimney.transformer.PartialUnwrapsOption=boolean
    • chimney.transformer.NonAnyValWrappers=boolean
    • chimney.transformer.ImplicitConflictResolution=Total/Partial/false
    • chimney.transformer.MacrosLogging=boolean
  • allow overriding every single Patcher (Boolean) flag
    • chimney.patcher.IgnoreRedundantPatcherFields=boolean
    • chimney.patcher.IgnoreNoneInPatch=boolean
    • chimney.patcher.MacrosLogging=boolean
  • allow providing comma-separated list of values to @SuppressWarnings(Array(...)) and @NoWarn(...)
    • chimney.SuppressWarnings=false/list
    • chimney.NoWarn=false/true/msg
  • docs
    • add a section about global flags override under scope-flags
    • add a section about all possible settings and default values

Copy link

codecov bot commented Jul 14, 2024

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 ⚠️
...letime/derivation/transformer/Configurations.scala 10.52% 17 Missing ⚠️
...d/chimney/internal/compiletime/ExprsPlatform.scala 56.66% 13 Missing ⚠️
...ternal/compiletime/derivation/GatewayCommons.scala 50.00% 5 Missing ⚠️
...ompiletime/derivation/patcher/Configurations.scala 28.57% 5 Missing ⚠️
...nal/compiletime/derivation/codec/CodecMacros.scala 93.33% 1 Missing ⚠️
...nternal/compiletime/derivation/iso/IsoMacros.scala 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MateuszKubuszok
Copy link
Member Author

I need to test somehow whether this change will not break #496 / #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
Copy link
Member Author

(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
Copy link
Member Author

MateuszKubuszok commented Jul 16, 2024

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
Copy link
Member Author

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.

@MateuszKubuszok MateuszKubuszok marked this pull request as ready for review July 17, 2024 10:04
@MateuszKubuszok MateuszKubuszok merged commit 8057162 into master Jul 17, 2024
22 of 24 checks passed
@MateuszKubuszok MateuszKubuszok deleted the xmacros-settings branch July 17, 2024 10:17
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

Successfully merging this pull request may close these issues.

1 participant