Comments (17)
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.
@codesurf42 if it's not macro:both
check if it also isn't (lack of) -Xss
flag.
from chimney.
a.patchUsing(b)
seems to be the culprit. a.using(b).patch
is working fine.
from chimney.
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.
Scala version is 2.13.12.
from chimney.
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.
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.
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.
We're already at -J-Xss64m
in our .sbtopts files.
from chimney.
But indeed the Scastie is working fine 😕
from chimney.
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.
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.
Please also add the option "-Xlint:unused"
.
from chimney.
Alternatively -Wunused:explicits
, -Wunused:params
, -Wunused:linted
, or -Wunused:implicits
.
Any of them in combination with -Wmacros:both
trigger the error.
from chimney.
Thanks!
from chimney.
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.
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)
- 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
- Cannot transform Scala class to Java class HOT 5
- Chimney stabilization into 1.0.0
- Exclude macro generated code from WartRemover checks HOT 14
- 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
- Chimney >= 0.8.0 can't transform case class with annotated parameter HOT 7
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.