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

Logging Macro Doesn't Support Scala2 + Scala3 Simultaneously #317

Open
Zeimyth opened this issue Jan 5, 2022 · 2 comments · May be fixed by #415
Open

Logging Macro Doesn't Support Scala2 + Scala3 Simultaneously #317

Zeimyth opened this issue Jan 5, 2022 · 2 comments · May be fixed by #415

Comments

@Zeimyth
Copy link

Zeimyth commented Jan 5, 2022

I am working in a Scala project that is in the middle of migrating from Scala 2 to Scala 3. We are trying to perform this migration in piecemeal, but the scala-logging library is currently making it difficult to do so.

In theory, there should be a way to implement Scala macros such that both Scala 2 and Scala 3 dependencies can depend on the library and call the macro code (see https://github.com/scalacenter/mix-macros-scala-2-and-3, an example repo put together to demonstrate how to do this). However, when attempting this with the scala-logging library (see Zeimyth/mix-macros-scala-2-and-3#1), the Scala 2 build gets these errors at compile time:

Main.scala:12:14: Unsupported Scala 3 inline macro method info; found in trait com.typesafe.scalalogging.LoggerImpl.
[error]   logger.info("Hello, World!")
[error]              ^
[error] one error found
[error] (app2 / Compile / compileIncremental) Compilation failed

I am not fluent enough in Scala macros (and certainly not in cross-version Scala macro support) to know exactly why the example repo's macro is supported in both Scala versions but the scala-logging one is not. I think it has to do with the way the example repo is defining a single source file that exposes both macros together: https://github.com/scalacenter/mix-macros-scala-2-and-3/blob/develop/testframework/src/main/scala/testframework/package.scala. Perhaps scala-logging needs something like this?

@Zeimyth
Copy link
Author

Zeimyth commented Feb 10, 2022

There hasn't been any discussion activity on this issue in the month since I opened it. Is anyone actively working on this issue who could share the status of it? I am trying to dig into the problem still myself in my spare time, but progress has been slow.

@seanrohead
Copy link

We are running into the same issue and would like a resolution for this as well

bishabosha added a commit to scala/scala3 that referenced this issue Oct 12, 2023
Fixes #16630

This PR fixes the above issue which affects cross scala2/3 projects that
use a common macro library as per
https://docs.scala-lang.org/scala3/guides/migration/tutorial-macro-mixing.html
, e.g. scala-logging is blocked from fixing this issue
lightbend-labs/scala-logging#317

The fix makes the scala 2 macro check read the Erased flag from the
initial flags rather than completing the RHS first. This will work in
the case of scala 2 macros because the erased flag is explicitly added
rather than being in the source code. However it relies on using an
"UNSAFE" value.
@johnduffell johnduffell linked a pull request Oct 17, 2023 that will close this issue
@jxnu-liguobin jxnu-liguobin linked a pull request Mar 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants