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

Regression in lowmelvin/hammer-scala #22585

Open
jchyb opened this issue Feb 12, 2025 · 1 comment · May be fixed by #22856
Open

Regression in lowmelvin/hammer-scala #22585

jchyb opened this issue Feb 12, 2025 · 1 comment · May be fixed by #22856
Assignees
Labels
area:inline area:metaprogramming:quotes Issues related to quotes and splices itype:bug regression This worked in a previous version but doesn't anymore

Comments

@jchyb
Copy link
Contributor

jchyb commented Feb 12, 2025

https://github.com/VirtusLab/community-build3/actions/runs/13209436977/job/36880173932#logs

Compiler version

Working: 3.6.3
Broken: 3.6.4-RC1

Minimized code

Macro.scala:

import scala.quoted.*

trait Hammer[I, O] {
  def hammer(input: I): O
}

object Hammer {
  inline def makeProductHammerMacro[I, O](): Hammer[I, O] =
    ${ makeProductHammerMacroImpl[I, O] }

  def makeProductHammerMacroImpl[I: Type, O: Type](using Quotes): Expr[Hammer[I, O]] =
    '{ makeHammer[I, O]() }

  inline def makeHammer[S, O](): Hammer[S, O] =
    new Hammer[S, O] {
      lazy val (hammer: Hammer[?, Int], idx: Int) = ???

      override def hammer(input: S): O = {
        hammer.hammer(???.asInstanceOf).asInstanceOf[O]
      }
    }
}

Main.scala:

object HammerSpec {
  case class A(x: Int)
  case class B(x: Int)
  Hammer.makeProductHammerMacro[A, B]()
}

Output

[error] -- [E007] Type Mismatch Error: /Users/jchyb/workspace/community-build3/repo/src/main/scala/com/melvinlow/hammer/instances.scala:5:37 
[error]  5 |  Hammer.makeProductHammerMacro[A, B]()
[error]    |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |  Found:    ?1.I
[error]    |  Required: Nothing
[error]    |
[error]    |  where:    ?1 is an unknown value of type Hammer[?, Int]
[error]    |----------------------------------------------------------------------------
[error]    |Inline stack trace
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from Hammer.scala:21
[error] 21 |        hammer.hammer(???.asInstanceOf).asInstanceOf[O]
[error]    |                      ^^^^^^^^^^^^^^^^
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from Hammer.scala:21
[error] 14 |    '{ makeHammer[I, O]() }
[error]    |       ^^^^^^^^^^^^^^^^^^
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from Hammer.scala:21
[error] 14 |    '{ makeHammer[I, O]() }
[error]    |       ^^^^^^^^^^^^^^^^^^
[error]     ----------------------------------------------------------------------------
[error]    |----------------------------------------------------------------------------
[error]    | Explanation (enabled by `-explain`)
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |
[error]    | Tree: ???.asInstanceOf[?1.I]
[error]    | I tried to show that
[error]    |   ?1.I
[error]    | conforms to
[error]    |   Nothing
[error]    | but none of the attempts shown below succeeded:
[error]    |
[error]    |   ==> ?1.I  <:  Nothing
[error]    |     ==> Any  <:  Nothing  = false
[error]    |
[error]    | The tests were made under the empty constraint
[error]     ----------------------------------------------------------------------------

Expectation

No error.
This minimisation is pretty finicky - getting rid of lazy val or the seemingly useless (in the context of this minimisation) macro makes the error disappear.

@jchyb jchyb added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 12, 2025
@Gedochao
Copy link
Contributor

Last good nightly: 3.6.4-RC1-bin-20241121-5d1d274-NIGHTLY
First bad nightly: 3.6.4-RC1-bin-20241122-64411b6-NIGHTLY
26ecda5 is the first bad commit
cc @dwijnand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:inline area:metaprogramming:quotes Issues related to quotes and splices itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
3 participants