Skip to content
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

Scala 3: Toplevel definition targetName is defined in... #4348

Closed
gvolpe opened this issue Nov 16, 2022 · 6 comments
Closed

Scala 3: Toplevel definition targetName is defined in... #4348

gvolpe opened this issue Nov 16, 2022 · 6 comments

Comments

@gvolpe
Copy link
Member

gvolpe commented Nov 16, 2022

Hi folks,

Has anyone have come across this issue when cross-compiling to JVM and JS using Scala 3? According to the release notes, Cats 2.8.0 is binary-compatible with 2.9.0, so I'm not sure if this issue is related to binary compatibility, it seems more of a duplication of top-level definitions both in cats-core and cats-core_sj1.

This started failing right after upgrading to Cats 2.9.0, you can find the full logs here, using Scala 3.2.2-RC1.

I also tried downgrading to the stable version 3.2.1, same issue.

[error] dotty.tools.dotc.core.TypeError: Toplevel definition targetName is defined in
[error]   /home/gvolpe/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-core_3/2.9.0/cats-core_3-2.9.0.jar(cats/compat/package.class)
[error] and also in
[error]   /home/gvolpe/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-core_sjs1_3/2.8.0/cats-core_sjs1_3-2.8.0.jar(cats/compat/compat$package.class)
[error] One of these files should be removed from the classpath.
[error] dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.dropStale$1(SymDenotations.scala:2447)
[error] dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.recur$5(SymDenotations.scala:2411)
[error] dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.computeMembersNamed(SymDenotations.scala:2467)
[error] dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2023)
[error] dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2074)
[error] dotty.tools.dotc.core.Types$Type.go$1(Types.scala:686)
[error] dotty.tools.dotc.core.Types$Type.findMember(Types.scala:879)

Any help would be much appreciated, as this is blocking me from upgrading to the latest Cats Effect version and all the dependencies built using the latest Cats version. Thank you! 🙏🏽

@armanbilge
Copy link
Member

Yup, I've seen this issue. Indeed the error message explains the problem perfectly:

[error] dotty.tools.dotc.core.TypeError: Toplevel definition targetName is defined in
[error]   /home/gvolpe/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-core_3/2.9.0/cats-core_3-2.9.0.jar(cats/compat/package.class)
[error] and also in
[error]   /home/gvolpe/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-core_sjs1_3/2.8.0/cats-core_sjs1_3-2.8.0.jar(cats/compat/compat$package.class)
[error] One of these files should be removed from the classpath.

I.e., don't put both cats-core_3-2.9.0 and cats-core_sjs1_3-2.8.0.jar on the same classpath :)

@armanbilge
Copy link
Member

The problem is here, among many places:
https://github.com/gvolpe/trading/blob/5b59dfdd29e5f767ea83f4fc6a73c3ac0b8fb080/build.sbt#L43

Adding JVM dependencies to Scala.js projects creates issues like this.

@gvolpe
Copy link
Member Author

gvolpe commented Nov 16, 2022

Oh thank you very much for the speedy response, @armanbilge ! I was looking at my build file struggling to see where the issue may be, I'll look into that dependency and see how I can solve it.

@armanbilge
Copy link
Member

@gvolpe it's probably not just that dependency. You need to carefully audit your dependencies and separate them into .settings, .jvmSettings, and .jsSettings.

@gvolpe
Copy link
Member Author

gvolpe commented Nov 16, 2022

Thanks @armanbilge , looking into it now. Wondering how the same build worked with previous versions, it must be a recent change, no?

@armanbilge
Copy link
Member

Yes, you are seeing an artifact of #4315 which landed in 2.9.0. That was a change to Cats private code, so it has no compatibility implications.

However, Scala 3 / TASTy appears to be a lot more brittle to these sort of build misspecifications.

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

No branches or pull requests

2 participants