Comments (5)
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.
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.
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.
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.
Thx @MateuszKubuszok. A note would be helpful for people who experience this issue for the first time.
from chimney.
Related Issues (20)
- Unexpected arity mismatch when mixing Tuple with `enableOptionDefaultsToNone` HOT 6
- Improve ReadTheDocs/MkDocs configuration
- Scary compiler error when providing Int const instead of Long HOT 3
- Compilation of partial transformation fails when there are fields named both `is{Name}` and `{name}` HOT 2
- Silent invalid behavior of `withFieldConst` when field name starts with "set" HOT 6
- [PartialTransformer] Field Option[Field].None to Proto3.Fields.Default
- ClassCastException thrown on Scala 3 when transforming sealed traits to Protobuf GeneratedEnum HOT 12
- Automatic Coproduct Rename from/to Protobuf GeneratedEnum HOT 8
- Can't transform coproduct - Java Enum to Sealed trait HOT 24
- Chimney stabilization into 1.0.0
- Exclude macro generated code from WartRemover checks HOT 16
- Fix Overrides for Subtypes matching
- Support seamless transformation of protobuf oneof types HOT 4
- Compiler bugs: known, relevant and unresolved/undocumented
- Support transformation to and from Java primitives
- Test more Scala CLI snippets for output (printed results)
- Support runtime-defined enums
- Rewrite Patchers as a special case of multiple case classes mapping
- Refactor internals to NOT rely on RuntimeDataStore
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chimney.