Git Product home page Git Product logo

Comments (17)

som-snytt avatar som-snytt commented on July 18, 2024 2

I commented on the Scala ticket that it is failing just sorting warnings by position: probably it's not defensive about unpositioned trees produced by the macro. In that case, the workaround is not to lint it with -Wmacros:both. I'll try to confirm that and provide a fix, since sort order should not be fatal.

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on July 18, 2024 1

@codesurf42 if it's not macro:both check if it also isn't (lack of) -Xss flag.

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

a.patchUsing(b) seems to be the culprit. a.using(b).patch is working fine.

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on July 18, 2024

Hey, thanks for the ticket!

I would need:

  • Scala version
  • some small reproduction

I don't see our macros in the stack trace, so I can only guess there is a bug in the compiler which we haven't triggered before and are triggering now(?). When I google NoPosition I see issues like scalameta/scalameta#1183 but the only position we are using is c.enclosingPosition, so I cannot tell anything more without any reproduction.

It doesn't have to be super minimized or using only Chimney, just remove all NDA-company-specific details.

Alternatively I found a similar ticker for scala/bug#10604. I am not sure if it is still relevant but you might try increasing the stack size and see if that's an issue with hidden StackOverflow inside a compiler.

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

Scala version is 2.13.12.

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

I was able to pinpoint the error to an interaction with Circe, specifically if there is a configured codec implicit val codec: Codec[Event] = io.circe.generic.extras.semiauto.deriveConfiguredCodec available for the class that is either patcher or patchee. io.circe.generic.semiauto.deriveCodec is working fine.

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024
import io.circe.Codec
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.semiauto.deriveConfiguredCodec
import io.circe.generic.semiauto.deriveCodec
import io.scalaland.chimney.dsl._

object ChimneyBug {
  private def handleEvent(state: State, event: Event) =
    (state, event) match {
      case (active: State.Active, updated: Event.A) =>
        //  Working: active.using(updated).patch
        active.patchUsing(updated)
    }

  sealed trait Event
  object Event {
    case class A(
                  a: String,
                ) extends Event

    implicit val configuration = Configuration.default.withDiscriminator("class").withDefaults
    implicit val codec: Codec[Event] = deriveConfiguredCodec
    // Working: implicit val codec: Codec[Event] = deriveCodec
  }
  
  sealed trait State
  object State {
    case class Active(
                       a: String,
                     ) extends State

    implicit val configuration = Configuration.default.withDiscriminator("class").withDefaults
    implicit val codec: Codec[State] = deriveConfiguredCodec
    // Working: implicit val codec: Codec[Event] = deriveCodec
  }
}

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on July 18, 2024

When I am testing your code in Scastie it compiles. Could you check if setting e.g. -Xss8m for Java options changes anything? It only needs to be changed for compilation, not for the deployment.

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

We're already at -J-Xss64m in our .sbtopts files.

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

But indeed the Scastie is working fine 😕

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

The issue seems to be with the compiler setting -Wmacros:both ("Lints code before and after applying a macro").

As soon as I disable this setting, the code compiles.

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on July 18, 2024

Unfortunatelly, I still cannot reproduce. I created this Scala CLI snippet, but it runs without issues.

//> using scala 2.13.12
//> using options -Wmacros:both -verbose -Xlog-implicits
//> using dep io.scalaland::chimney::0.8.0
//> using dep io.circe::circe-generic::0.14.6
//> using dep io.circe::circe-generic-extras::0.14.3

import io.circe.Codec
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.semiauto.deriveConfiguredCodec
import io.circe.generic.semiauto.deriveCodec
import io.scalaland.chimney.dsl._

object ChimneyBug {
  private def handleEvent(state: State, event: Event) =
    (state, event) match {
      case (active: State.Active, updated: Event.A) =>
        //  Working: active.using(updated).patch
        active.patchUsing(updated)
    }

  sealed trait Event
  object Event {
    case class A(
                  a: String,
                ) extends Event

    implicit val configuration = Configuration.default.withDiscriminator("class").withDefaults
    implicit val codec: Codec[Event] = deriveConfiguredCodec
    // Working: implicit val codec: Codec[Event] = deriveCodec
  }

  sealed trait State
  object State {
    case class Active(
                       a: String,
                     ) extends State

    implicit val configuration = Configuration.default.withDiscriminator("class").withDefaults
    implicit val codec: Codec[State] = deriveConfiguredCodec
    // Working: implicit val codec: Codec[Event] = deriveCodec
  }

  def test = handleEvent(ChimneyBug.State.Active("A"), ChimneyBug.Event.A("B"))
}

object Main {
  def main(args: Array[String]): Unit =
    println(ChimneyBug.test)
}
scala-cli run .
Compiling project (Scala 2.13.12, JVM)
[a lot of verbose logs]
Compiled project (Scala 2.13.12, JVM)
Active(B)

There must be something more to your setup which produces the error. Do you use the newest sbt, are you using Windows?

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

Please also add the option "-Xlint:unused".

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

Alternatively -Wunused:explicits, -Wunused:params, -Wunused:linted, or -Wunused:implicits.

Any of them in combination with -Wmacros:both trigger the error.

from chimney.

mariussoutier avatar mariussoutier commented on July 18, 2024

Thanks!

from chimney.

codesurf42 avatar codesurf42 commented on July 18, 2024

I have seen these errors quite often recently in my code base (using upgraded to 0.8.0 chimney for conversions to scalapb-generated hierarchy), usually appearing at some point when adding more and more of data structures. The only pattern I have found was related to missing internal conversions in the ADT for chimney, however instead of expected macro compile error for missing transformations, it was bluntly reported by NoPosition.
We don't use macros:both.
Scala 2.13.9 and 2.13.12
If I find it again, I can try to extract it.

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on July 18, 2024

Since this issue seem to be related to a compiler's bug, I'll close it for now. When the fix is released I'll add the information about it to the documentation.

from chimney.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.