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

Type check failure with AnyVal and Type alias #11849

Open
remyhaemmerle-da opened this issue Jan 15, 2020 · 1 comment
Open

Type check failure with AnyVal and Type alias #11849

remyhaemmerle-da opened this issue Jan 15, 2020 · 1 comment
Milestone

Comments

@remyhaemmerle-da
Copy link

@remyhaemmerle-da remyhaemmerle-da commented Jan 15, 2020

Scala version: 1.12.6, 1.12.10, 1.13.1

The compiler rejects the following program

sealed abstract class Builder[Y] {
  type This = Builder[Y]
  def add(s: Int): This  = ???
}

object Builder{
  implicit class BuilderOps[XX](val builder: Builder[XX]) extends AnyVal {
    def add(s: Seq[Int]): Builder[XX] = s.foldLeft(builder.add(s.length))(_ add _)
  }
}

with the following error message:

[error] .../src/main/scala/Main.scala:18:77: type mismatch;
[error]  found   : Builder[XX]
[error]  required: Builder[XX]
[error]     def add(s: Seq[Int]): Builder[XX] = s.foldLeft(builder.add(s.length))(_ add _)
[error]                                                                             ^
[error] one error found

The compilation succeeds if either:

  • I inline This
  • I drop the extends AnyVal
@joroKr21

This comment has been minimized.

Copy link

@joroKr21 joroKr21 commented Jan 16, 2020

Sounds a lot like #11383

@lrytz lrytz added this to the Backlog milestone Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.