Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@roald-di
Copy link
Contributor

@roald-di roald-di commented Jun 23, 2021

Fixes #5152

The problem was that the .sjsir files are only generated when the compiler gets passed the -scalajs option, this option is correctly added by the scalajs plugin but was then lost when setting scalac options.

I also had to add a type signature in ZScope.scala as it would not compile with -scalajs, showing this error:

[error] -- Error: \zio\core\shared\src\main\scala\zio\ZScope.scala:309:57
[error] 309 |              (l: OrderedFinalizer, r: OrderedFinalizer) => if (l eq null) -1 else if (r eq null) 1 else l.order - r.order
[error]     |                                                         ^
[error]     |object creation impossible, since def compare(x$0: T, x$1: T): Int in trait Comparator in package java.util is not defined
[error]     |(The class implements a member with a different type: final def compare
[error]     |  (l: zio.ZScope.OrderedFinalizer, r: zio.ZScope.OrderedFinalizer): Int in anonymous class Object with
[error]     |  java.util.Comparator[? >: zio.ZScope.OrderedFinalizer]
[error]     | {...})
[error] one error found

this is probably a compiler bug? I didn't want to invest a lot of time figuring this out since the workaround is pretty easy.

To validate my change I did a publishLocal and checked that the files are included.
I also verified with println that the original scalac options are always empty except for when they contain the single -scalajs switch, this means that the rest of the build should not be impacted by this change.

@CLAassistant
Copy link

CLAassistant commented Jun 23, 2021

CLA assistant check
All committers have signed the CLA.

@ghostdogpr
Copy link
Member

Great news! Glad someone finally figured it out 👏

adamgfraser
adamgfraser previously approved these changes Jun 23, 2021
@roald-di
Copy link
Contributor Author

roald-di commented Jun 23, 2021

Ok, I think that I'm going to need some help fixing that assertTrue macro..

I have taken a look but I don't quite know how to approach this.

The test that fails to compile under scalajs is this one:

test("Object constructor") {
    assertTrue(zio.duration.Duration.fromNanos(1000) == zio.duration.Duration.Zero)
}

The output of the macro is approximately this

zio.test.Arrow.succeed[zio](zio)
    .>>>[zio.duration](zio.test.Arrow.fromFunction[zio, zio.duration](((from: zio) => from.duration)))
    .>>>[zio.duration.package.type](zio.test.Arrow.fromFunction[zio.duration, zio.duration.package.type]((from: zio.duration) => from))
    .>>>[zio.duration.Duration.type](zio.test.Arrow.fromFunction[zio.duration.package.type, zio.duration.Duration.type]((from: zio.duration.package.type) => from.Duration))
    .>>>[java.time.Duration](zio.test.Arrow.fromFunction[zio.duration.Duration.type, java.time.Duration]((from: zio.duration.Duration.type) => from.fromNanos(1000L)))
    .>>>[scala.Boolean](zio.test.Assertions.equalTo[java.time.Duration](zio.duration.Duration.Zero)(zio.test.OptionalImplicit.none[zio.test.Diff[java.time.Duration]]))

the first line already fails to translate to js with the error

java.lang.AssertionError: assertion failed: Cannot use package as value: Select(This(Ident(<root>)),zio)

which makes sense? trying to compile that line with scalac will fail with the similar error package zio is not a value

why is this even working on the jvm?

so I'm not sure what to do, should this be supported by scalajs, should the macro output something different, like

zio.test.Arrow.succeed[zio.duration.Duration.type](zio.duration.Duration)
    .>>>[java.time.Duration](zio.test.Arrow.fromFunction[zio.duration.Duration.type, java.time.Duration]((from: zio.duration.Duration.type) => from.fromNanos(1000L)))
    .>>>[scala.Boolean](zio.test.Assertions.equalTo[java.time.Duration](zio.duration.Duration.Zero)(zio.test.OptionalImplicit.none[zio.test.Diff[java.time.Duration]]))

or something else?

@roald-di
Copy link
Contributor Author

Turns out this was not working on the jvm either, I opened a separate issue for that: #5244

@roald-di
Copy link
Contributor Author

@adamgfraser can we try running ci again to see if this works now?

@ghostdogpr
Copy link
Member

@roald-di can you rebase to the latest master, so that your other PR is included? That should re-trigger the CI.

@adamgfraser adamgfraser merged commit 97dabc0 into zio:master Jun 28, 2021
@roald-di roald-di deleted the 5152 branch June 28, 2021 17:28
@ghostdogpr
Copy link
Member

I just checked the JAR from the latest snapshot and .sjsir files are included 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing sjsir files in Scala 3 jars for Scala.js

4 participants