Skip to content

TypeMismatchError compiling inline infix method with this #11866

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
japgolly opened this issue Mar 24, 2021 · 2 comments · Fixed by #11886
Closed

TypeMismatchError compiling inline infix method with this #11866

japgolly opened this issue Mar 24, 2021 · 2 comments · Fixed by #11886
Assignees
Milestone

Comments

@japgolly
Copy link
Contributor

Compiler version

3.0.0-RC1

Minimized code

type Callback = CallbackTo[Unit]

final class CallbackTo[+A] { self =>

  def >>[B](y: CallbackTo[B]): CallbackTo[B] =
    ???

  inline def *>[B](z: CallbackTo[B]): CallbackTo[B] =
    >>(z)

  def qwe: CallbackTo[A] = {
    def x: Callback = ???
    val hmmm = this

    x *> this // error
    x *> self // error
    x *> hmmm // ok

    ???
  }
}

Output

-- [E007] Type Mismatch Error: x.scala:15:4 ------------------------------------
15 |    x *> this // error
   |    ^^^^^^^^^
   |    Found:    (CallbackTo_this : Callback)
   |    Required: CallbackTo[A]
-- [E007] Type Mismatch Error: x.scala:16:4 ------------------------------------
16 |    x *> self // error
   |    ^^^^^^^^^
   |    Found:    (CallbackTo_this : Callback)
   |    Required: CallbackTo[A]

Expectation

It should compile.

@smarter
Copy link
Member

smarter commented Mar 24, 2021

x *> this gets inlined to:

        {
          val CallbackTo_this: Callback = x
          CallbackTo_this.>>[A](CallbackTo_this):CallbackTo[Unit]
        }

so this was incorrectly substituted by a completely different variable, and that was only caught because they had a different type, this looks fairly serious to me so I'm putting it in the RC2 milestone but I'll let @nicolasstucki decide if that's fixable by then or not.

@smarter smarter added this to the 3.0.0-RC2 milestone Mar 24, 2021
@odersky
Copy link
Contributor

odersky commented Mar 24, 2021

I'll take a look

@odersky odersky self-assigned this Mar 24, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Mar 24, 2021
@Kordyjan Kordyjan modified the milestones: 3.0.0-RC2, 3.0.0 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