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

Macro in class with private implementation from companion object #15413

Closed
prolativ opened this issue Jun 9, 2022 · 1 comment · Fixed by #18405
Closed

Macro in class with private implementation from companion object #15413

prolativ opened this issue Jun 9, 2022 · 1 comment · Fixed by #18405
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug

Comments

@prolativ
Copy link
Contributor

prolativ commented Jun 9, 2022

Compiler version

3.2.0-RC1-bin-20220607-76a0b29-NIGHTLY

Minimized code

//> using scala "3.2.0-RC1-bin-20220607-76a0b29-NIGHTLY"

import scala.quoted.*

class Macro:
  inline def foo = ${ Macro.fooImpl }

object Macro:
  private def fooImpl(using Quotes) = '{}

Output

[error] MalformedMacro.scala:6:23: Malformed macro.
[error] 
[error] Expected the splice ${...} to contain a single call to a static method.
[error]   inline def foo = ${ Macro.fooImpl }
[error]

Expectation

This seems wrong to me although I'm not sure what the correct behaviour should be as I see two options:

  • Fix the error message (currently it doesn't say that a macro implementation cannot be private)
  • Make this compile

Note that if the inline def is inside the object, everything compiles successfully:

import scala.quoted.*

object Macro:
  inline def foo = ${ Macro.fooImpl }
  private def fooImpl(using Quotes) = '{}
@nicolasstucki
Copy link
Contributor

The inline accessor inline$fooImpl is generated in the wrong place. It should have been placed in the module. This is similar to #13215.

sbt:scala3> scalac Main.scala -Xprint:typer
-- Error: Main.scala:6:28 ------------------------------------------------------
6 |  inline def foo: Unit = ${ Macro.fooImpl }
  |                            ^^^^^^^^^^^^^
  |   Malformed macro.
  |
  |   Expected the splice ${...} to contain a single call to a static method.
[[syntax trees at end of                     typer]] // Main.scala
package <empty> {
  import scala.quoted.*
  class Macro() extends Object() {
    def foo: Unit
    final def inline$fooImpl(using x$1: quoted.Quotes): quoted.Expr[Unit] = 
      Macro.fooImpl(x$1)
  }
  final lazy module val Macro: Macro = new Macro()
  final module class Macro() extends Object() { this: Macro.type =>
    private[this] def fooImpl(using x$1: quoted.Quotes): quoted.Expr[Unit] = ???
  }
}

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 1, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 1, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 1, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 1, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 1, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 3, 2023
If a class `C` needs inline accessors that would be added top-level
or if the accessor is to a static members, we place it in a new
invisible module `C$inline$accessors`.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backwards binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 3, 2023
If a class `C` needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in a new
invisible module `C$inline$accessors`.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 3, 2023
If a class `C` needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in a new
invisible module `C$inline$accessors`.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 6, 2023
If a class `C` needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in a new
invisible module `C$inline$accessors`.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 7, 2023
If a class `C` needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in a new
invisible module `C$inline$accessors`.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 7, 2023
If a class `C` needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in a new
invisible module `C$inline$accessors`.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 7, 2023
If a class `C` needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in a new
invisible module `C$inline$accessors`.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 21, 2023
If a class needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in the top-level
class as a java static method.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 21, 2023
If a class needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in the top-level
class as a java static method.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 21, 2023
If a class needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in the top-level
class as a java static method.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 21, 2023
If a class needs inline accessors that would be added top-level
or if the accessor is to a static member, we place it in the top-level
class as a java static method.

If the accessor location in the new scheme is not the same as the
previous location, we also generate the old accessor for backward binary
compatibility but do not use it.

Fixes scala#13215
Fixes scala#15413
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 23, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 23, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 23, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 23, 2023
Part of the fix for scala#15413
Part of the fix for scala#16983
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 16, 2023
If non-static inline accessor is generated we do not we can tell the
user why they cannot access the macro implementation this way.

Currently we do not have a clean way to fix this code, but in the future [SIP-58](scala/improvement-proposals#58)
would introduce a way to not generate this accessor.

Fixes scala#15413
nicolasstucki added a commit that referenced this issue Aug 17, 2023
If non-static inline accessor is generated we do not we can tell the
user why they cannot access the macro implementation this way.

Currently we do not have a clean way to fix this code, but in the future
[SIP-58](scala/improvement-proposals#58) would
introduce a way to not generate this accessor.

Fixes #15413
WojciechMazur pushed a commit that referenced this issue Jun 19, 2024
If non-static inline accessor is generated we do not we can tell the
user why they cannot access the macro implementation this way.

Currently we do not have a clean way to fix this code, but in the future [SIP-58](scala/improvement-proposals#58)
would introduce a way to not generate this accessor.

Fixes #15413

[Cherry-picked f1db208]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment