Git Product home page Git Product logo

Comments (5)

MateuszKubuszok avatar MateuszKubuszok commented on August 17, 2024 1

I injected some debug code into our utilities to check the behavior:

    def isPOJO[A](implicit A: Type[A]): Boolean = {
      val sym = TypeRepr.of(using A).typeSymbol
      // extra logic for debugging
      if sym.toString.contains("PersonJava") then {
        println(sym)
        println(sym.primaryConstructor)
        println(sym.primaryConstructor.isPublic) // our extension method based on flags
        println(sym.primaryConstructor.flags.show)
      }
      !A.isPrimitive && !(A <:< Type[String]) && sym.isClassDef && !sym.isAbstract && sym.primaryConstructor.isPublic
    }

for target

public class PersonJava {
    // private doesn't work when Java -> Scala case class
    // use enable bean getters, then it works
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public PersonJava(String name) {
        this.name = name;
    }
}

it gave me

class PersonJava
method <init>
false
Flags.JavaDefined | Flags.Local | Flags.Method | Flags.Private | Flags.PrivateLocal

As far as I can tell it's a bug in Scala 3 macros - public constructor is flagged as Private so Chimney's behavior is quite correct assuming that compiler is not lying.

@jchyb should I report you a bug?

from chimney.

frevib avatar frevib commented on August 17, 2024

Could above issue also be something that works sometimes, and sometimes not? I see it now working in another project:

    private def mapSizeTrace(sizeTrace: ScalaTrace): JavaTrace = {
      sizeTrace
        .into[JavaTrace]
        .withFieldComputed(_.getId, _.id)
        .withFieldComputed(_.getName, _.name)
        .transform
    }

We earlier had some issues with Chimney in a Scala 2.13 not picking up some mappings, while for other classes it did pick up the mappings. We then decided to get rid of it as we didn't understand what was going on. Am I missing something? Is there more known about Chimney acting inconsistent?

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on August 17, 2024

We earlier had some issues with Chimney in a Scala 2.13 not picking up some mappings, while for other classes it did pick up the mappings.

Which mappings? Implicits? Automatic matching of fields? Manual overrides? .enableMacrosLogging should tell more about what macro attempted to do and why. Without this information we are only guessing.

Is there more known about Chimney acting inconsistent?

The only inconsistencies that I know of are https://chimney.readthedocs.io/en/stable/troubleshooting/#sealed-traits-fail-to-recompile or https://chimney.readthedocs.io/en/stable/troubleshooting/#javalangunsupportedoperationexception-positionpoint-on-noposition-error . Both are a result of a buggy Scala 2 compiler behavior that Chimney would never be able to fix (here one of them is won't fix, you just have to clean and compile again, and the other is fixed in newest 2.13).

There were also some cases when Scala 2 had a bug which were marked as wontfix but which could be worked around in the code - that is when you learned that there is a workaround to apply when you received a bug report, e.g. https://github.com/scalalandio/chimney/blob/master/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala#L31 .

Whether this bug is one of these cases might be something I learn when I'll have some time to investigate and reproduce the bug (no ETA on this).

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on August 17, 2024

I'll close this ticket - there is nothing I can do in Chimney to fix it, and once it will get fixed in the compiler then Chimney will receive the correct behavior as well. Optionally, I could add a note in the docs that compiler upgrade is recommended when the fix is released.

from chimney.

frevib avatar frevib commented on August 17, 2024

Thx @MateuszKubuszok. A note would be helpful for people who experience this issue for the first time.

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.