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

Context bound desugared at the wrong place in extension method #11586

Closed
rjolly opened this issue Mar 3, 2021 · 5 comments · Fixed by #11623
Closed

Context bound desugared at the wrong place in extension method #11586

rjolly opened this issue Mar 3, 2021 · 5 comments · Fixed by #11623
Milestone

Comments

@rjolly
Copy link
Contributor

rjolly commented Mar 3, 2021

Compiler version

3.0.0-RC1

Minimized code

trait Conv[T]

extension [T: Conv](x: T)
  def combine (y: T): T = ???

Compiler output with -Xprint:typer

    extension [T >: Nothing <: Any](x: T) def combine(y: T)(
      implicit evidence$1: test.Conv[T]
    ): T = ???

Expectation

    extension [T >: Nothing <: Any](x: T)(using x$2: test.Conv[T]) def combine(
      y: T
    ): T = ???

, obtained with "using" syntax:

extension [T](x: T)(using Conv[T])
  def combine (y: T): T = ???
@odersky
Copy link
Contributor

odersky commented Mar 3, 2021

The current definition and implementation looks more useful since it allows to pass a Conv[T] explicitly.

@odersky odersky closed this as completed Mar 3, 2021
@prolativ
Copy link
Contributor

prolativ commented Mar 3, 2021

@odersky IMHO the suggested desugaring makes more sense and it still makes it possible to pass Conv[T] explicitly although the order of arguments would be different

"abc".combine(using given_Conv_String)("def")

@neko-kai
Copy link
Contributor

neko-kai commented Mar 3, 2021

@odersky
Useful or not, I believe it's unintuitive, irregular and without precedent.

The precedent that def x[T: U](a: A) is interchangeable with def x[T](a: A)(using U[T]) is broken here in a way that's very hard to explain when writing, teaching or even performing code reviews.

How would I explain why I wrote using U[T] in once place where [T: U] would obviously be shorter to someone reviewing my changes? That would require writing a whole paragraph explaining the difference in type inference, and why the context bound would not work just for this particular case even though usually it means the same thing. This is just for a minor and strange syntactic glitch, it would be very hard to justify why there's a difference in this particular in an otherwise completely intiuitive syntax.

@rjolly
Copy link
Contributor Author

rjolly commented Mar 3, 2021

@odersky To pass it explicitely you also have the raw form combine("abc")(using given_Conv_String)("def").

@rjolly
Copy link
Contributor Author

rjolly commented Mar 4, 2021

@odersky I understand it if you don' have time for this, but can we keep the issue open so that others can take over. Thanks!

rjolly added a commit to rjolly/dotty that referenced this issue Mar 4, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 5, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 5, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 5, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 5, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 5, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 5, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 5, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 5, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 8, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 8, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 8, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 8, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 8, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 8, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 8, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 9, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 13, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 13, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 13, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 13, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue Mar 15, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 25, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 25, 2021
rjolly added a commit to rjolly/dotty that referenced this issue Mar 25, 2021
@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