Skip to content

Regression macro between M3 and RC1 - transparent inline #11437

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

Closed
julien-truffaut opened this issue Feb 17, 2021 · 8 comments · Fixed by #11440
Closed

Regression macro between M3 and RC1 - transparent inline #11437

julien-truffaut opened this issue Feb 17, 2021 · 8 comments · Fixed by #11440

Comments

@julien-truffaut
Copy link

Compiler version

This is an error we encountered when migrating Monocle from Scala 3.0.0-M3 to 3.0.0-RC1.

Here is the link to the build: https://github.com/optics-dev/Monocle/runs/1917837206

Minimized code

object GenPrism {
  transparent inline def apply[Source, Target <: Source] = 
    Focus[Source](_.as[Target])
}

object Focus {

  def apply[S] = new MkFocus[S]

  class MkFocus[From] {
    transparent inline def apply[To](inline lambda: (From => To)): Any = 
      ${ FocusImpl('lambda) }
  }
}

Output

[error] -- Error: /Users/julien/project/Monocle/macro/src/main/scala-3.x/monocle/macros/GenPrism.scala:8:22
[error] 8 |    Focus[Source](_.as[Target])
[error]   |                  ^^^^^^^^^^^^
[error]   |              class Nothing in package scala does not take type parameters
[error] -- Error: /Users/julien/project/Monocle/macro/src/main/scala-3.x/monocle/macros/GenPrism.scala:7:25
[error] 7 |  transparent inline def apply[Source, Target <: Source] =
[error]   |                         ^
[error]   |                         `transparent` can only be used for inline methods

Expectation

@nicolasstucki
Copy link
Contributor

The error is with the missing as operation. Then that courses the compiler to give a wrong error for the inline definition.

If we fix the as then the transparent error disapears.

@nicolasstucki nicolasstucki added area:inline area:reporting Error reporting including formatting, implicit suggestions, etc and removed area:reporting Error reporting including formatting, implicit suggestions, etc labels Feb 17, 2021
@smarter
Copy link
Member

smarter commented Feb 17, 2021

(I recommend you add monocle to the Scala 3 build so this sort of things can be caught early: https://github.com/lampepfl/dotty/blob/master/community-build/README.md)

@smarter
Copy link
Member

smarter commented Feb 17, 2021

And as Nicolas said, your code snippet does not define as, so it seems that you minimized it too much (and found another issue with the compiler not reporting the missing definition)

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Feb 17, 2021

Minimized

transparent inline def foo = error
-- [E006] Not Found Error: Foo.scala:1:29 --------------------------------------
1 |transparent inline def foo = error
  |                             ^^^^^
  |                             Not found: error

longer explanation available when compiling with `-explain`
-- Error: Foo.scala:1:23 -------------------------------------------------------
1 |transparent inline def foo = error
  |                       ^
  |                       `transparent` can only be used for inline methods
2 errors found

@julien-truffaut
Copy link
Author

Thanks, I wasn't sure how to minimise it. Though I don't understand why it stopped working between M3 and RC1.

@smarter Thanks for pointing out the community build, I will look at adding Monocle

@smarter
Copy link
Member

smarter commented Feb 17, 2021

Though I don't understand why it stopped working between M3 and RC1.

Are you sure it worked before? It looks like the problematic code was added only a few days ago and without tests: https://github.com/optics-dev/Monocle/pull/1063/files, so it may have just been (incorrectly) compiling.

@kenbot
Copy link

kenbot commented Feb 17, 2021

Apologies for the lack of clarity in the snippet, the as extension method is brought in scope by import monocle.Focus._, and as the PR is just swapping out the implementation for existing functionality, the original tests are still in place and did not require modification.

@smarter
Copy link
Member

smarter commented Feb 17, 2021

Can you open an issue with the as method present that reproduces the problem?

@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants