-
Notifications
You must be signed in to change notification settings - Fork 396
zio-prelude compilation fails with ScalaJS 1.18.x #5127
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
Comments
There's a simpler example in [[syntax trees at end of pickler]] // CustomFunctionExample.scala
package examples {
import zio.prelude._;
object CustomFunctionExample extends scala.AnyRef {
def <init>(): examples.CustomFunctionExample.type = {
CustomFunctionExample.super.<init>();
()
};
object Palindrome extends zio.prelude.Newtype[String] {
def <init>(): examples.CustomFunctionExample.Palindrome.type = {
Palindrome.super.<init>();
()
};
override def assertion: zio.prelude.QuotedAssertion[String]{def magic: Int} = {
final class $anon extends AnyRef with zio.prelude.QuotedAssertion[String] {
def <init>(): <$anon: zio.prelude.QuotedAssertion[String]> = {
$anon.super.<init>();
()
};
def magic: Int = 42;
def run(value: String): scala.util.Either[zio.prelude.AssertionError,Unit] =
((str: String) =>
if (scala.Predef.augmentString(str).reverse.==(str))
scala.`package`.Right.apply[Nothing, Unit](())
else
scala.`package`.Left.apply[zio.prelude.AssertionError.Failure, Nothing](zio.prelude.AssertionError.Failure.apply("isPalindrome"))
).apply(value)
};
new $anon()
}
};
zio.prelude.Newtype.unsafeWrap[examples.CustomFunctionExample.Palindrome.type](CustomFunctionExample.this.Palindrome)("racecar")
}
} [[syntax trees at end of mixin]] // CustomFunctionExample.scala
package examples {
object CustomFunctionExample extends Object {
def <init>(): examples.CustomFunctionExample.type = {
CustomFunctionExample.super.<init>();
zio.prelude.Newtype.unsafeWrap(examples.CustomFunctionExample$Palindrome, "racecar");
()
}
};
object CustomFunctionExample$Palindrome extends zio.prelude.Newtype {
override def assertion(): zio.prelude.QuotedAssertion = new <$anon: zio.prelude.QuotedAssertion>();
final <artifact> private[this] def $anonfun$assertion$1(str: String): scala.util.Either =
if (scala.collection.StringOps.reverse$extension(scala.Predef.augmentString(str)).==(str))
new scala.util.Right(scala.runtime.BoxedUnit.UNIT)
else
new scala.util.Left(new zio.prelude.AssertionError$Failure("isPalindrome"));
def <init>(): examples.CustomFunctionExample$Palindrome.type = {
CustomFunctionExample$Palindrome.super.<init>();
()
}
};
final class anon$1 extends Object with zio.prelude.QuotedAssertion {
def run(value: String): scala.util.Either =
{
((str: String) => CustomFunctionExample$Palindrome.this.$anonfun$assertion$1(str))
}.apply(value).$asInstanceOf[scala.util.Either]();
<bridge> <artifact> def run(value: Object): scala.util.Either = anon$1.this.run(value.$asInstanceOf[String]());
def <init>(): <$anon: zio.prelude.QuotedAssertion> = {
anon$1.super.<init>();
()
}
}
} In the last snippet we see something funny. We have a lambda It breaks the new codegen we introduced in #5081 . But I also struggle to understand how the old codegen could deal with that? 🤔 I suspect that a macro or even a compiler plugin is responsible for generating that unexpected code pattern. @guizmaii Do you have any insight into that? |
Indeed, it looks like that code is the result of the following macro: def assertCustom_impl[A: c.WeakTypeTag](f: c.Tree): c.Tree = {
val (_, _, codeString) = text(f)
q"""
new _root_.zio.prelude.QuotedAssertion[${c.weakTypeOf[A]}] {
@_root_.zio.prelude.assertionLambdaQuote($f)
@_root_.zio.prelude.assertionString($codeString)
def magic = 42
def run(value: ${c.weakTypeOf[A]}): _root_.scala.util.Either[_root_.zio.prelude.AssertionError, _root_.scala.Unit] =
$f(value)
}
"""
} That macro seems to splice in |
Passing |
* Update sbt-scalajs, scalajs-compiler, ... to 1.18.2 * Give a try to the solution provided by @ghik here: scala-js/scala-js#5127 (comment) --------- Co-authored-by: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> Co-authored-by: Jules Ivanic <jules.ivanic@gmail.com>
Thanks for your help mates! I made the fix @ghik was suggested and the tests pass 🙂 |
Uh oh!
There was an error while loading. Please reload this page.
When compiling zio-prelude with ScalaJS 1.18.x, the compilation fails with multiple errors:
The PR updating SclaJS can be found here: zio/zio-prelude#1462
The CI build failing can be found here: https://github.com/zio/zio-prelude/actions/runs/13171977585/job/36763853813
NewtypeSpecTypes212.scala
code is:The code in
ForEachSpec.scala
failing to compile seems to be the following one:To reproduce locally, clone the repo and launch in an sbt console:
The text was updated successfully, but these errors were encountered: