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 for method dispatch in 7mind/izumi #21307

Closed
WojciechMazur opened this issue Jul 31, 2024 · 7 comments
Closed

Regression for method dispatch in 7mind/izumi #21307

WojciechMazur opened this issue Jul 31, 2024 · 7 comments
Assignees
Labels
area:overloading area:typer itype:bug regression This worked in a previous version but doesn't anymore stat:wontfix

Comments

@WojciechMazur
Copy link
Contributor

Compiler version

Last good release: 3.6.0-RC1-bin-20240719-af933c4-NIGHTLY
First bad release: 3.6.0-RC1-bin-20240723-46ff151-NIGHTLY

Bisect scripts failed to build the compiler for some revisions, the first bad commit could be any of:
3b3b8a7
637b1d3
2cfc561
875af44
dec395b

Minimized code

trait IO2[F[_, _]]:
  def apply[A](effect: => A): F[Throwable, A] = ???

trait  syntax:
  def IO2[F[_, _], A](effect: => A)(implicit F: IO2[F]): F[Throwable, A] = ???
  def IO2[F[_, _]: IO2]: IO2[F] = ???

class Test extends syntax:
  class X[F[_, _]: IO2]:
    def fails = IO2(println("hello world!"))
    def works = IO2(println("hello world!"))(using summon[IO2[F]])

Output

[error] ./src/test.scala:10:17
[error] Ambiguous overload. The overloaded alternatives of method IO2 in trait syntax with types
[error]  [F[_$5,_$6]](using evidence$1: IO2[F]): IO2[F]
[error]  [F[_$3,_$4], A](effect: => A)(implicit F: IO2[F]): F[Throwable, A]
[error] both match arguments (Unit)
[error]     def fails = IO2(println("hello world!"))
[error]                 ^^^

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:typer regression This worked in a previous version but doesn't anymore labels Jul 31, 2024
@Gedochao
Copy link
Contributor

cc @kasiaMarek @tgodzik

@tgodzik
Copy link
Contributor

tgodzik commented Aug 22, 2024

Wait, that's not possible. None of these commits touch the compiler itself. It's only related to the presentation compiler module

@tgodzik
Copy link
Contributor

tgodzik commented Aug 22, 2024

Could this just be flaky?

@dwijnand
Copy link
Member

dwijnand commented Aug 22, 2024

In af933c4...46ff151 #21226 looks like the best candidate, with #21248 as a fallback. Those commits mentioned don't even seem to be part of the commit range. Is the commit message auto-generated by a script? Because I think there's a bug in the script.

@dwijnand
Copy link
Member

Btw, this continues to not compile for me locally on main, which is a2c53a1. cc @EugeneFlesselle who's been active on the given prio change changes.

@EugeneFlesselle EugeneFlesselle self-assigned this Aug 31, 2024
@EugeneFlesselle
Copy link
Contributor

EugeneFlesselle commented Aug 31, 2024

The issue minimizes to:

trait P[X]
given P[Int] with {}

def foo[F]()(implicit p: P[F]): F = ???
def foo[F: P]: () => F = ???

def works = foo()(using summon[P[Int]])
def fails = foo()

It is introduced by Switch mapping of context bounds to using clauses in 3.6 #21257.
The 2nd foo definition was/is equivalent to

  • def foo[F](implicit ev: P[F]): () => F = ??? before the changes,
  • def foo[F](using P[F]): () => F after the changes.

With the 2nd version, we have the same error both before and after the changes:

11 |def fails = foo()
   |            ^^^
   |Ambiguous overload. The overloaded alternatives of method foo with types
   | [F](using x$1: P[F]): () => F
   | [F]()(implicit p: P[F]): F
   |both match arguments ()
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   | There are 2 methods that could be referenced as the compiler knows too little
   | about the expected type.
   | You may specify the expected type e.g. by
   | - assigning it to a value with a specified type, or
   | - adding a type ascription as in instance.myMethod: String => Int
    ----------------------------------------------------------------------------

I believe this is an intended change in behavior of #21257. Unless it is causing too many regressions, this should probably be a won't-fix. \cc @WojciechMazur @Gedochao


A trivial, but unideal, user-code fix would be to manually make the context bound an implicit argument in the 2nd def IO2. A better fix would be to, as the error message suggests, use an ascription:

def fails = (IO2: IO2[F])(println("hello world!")) // now works

@Gedochao
Copy link
Contributor

Gedochao commented Sep 3, 2024

I believe this is an intended change in behavior of #21257. Unless it is causing too many regressions, this should probably be a won't-fix.

@EugeneFlesselle agreed. Closing this as won'tfix

@Gedochao Gedochao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:overloading area:typer itype:bug regression This worked in a previous version but doesn't anymore stat:wontfix
Projects
None yet
Development

No branches or pull requests

5 participants