Skip to content

Recursive match type fails to compile #8449

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
weihsiu opened this issue Mar 6, 2020 · 2 comments · Fixed by #8451
Closed

Recursive match type fails to compile #8449

weihsiu opened this issue Mar 6, 2020 · 2 comments · Fixed by #8451
Assignees

Comments

@weihsiu
Copy link

weihsiu commented Mar 6, 2020

dotty version: 0.22.0-RC1
I've also tried dotty nightly but it also failed as well.

minimized code

type Fib[N <: Int] <: Int = N match {
  case 0 => 0
  case 1 => 1
  case _ => Fib[Fib[N - 1] + Fib[N - 2]]
}
val fib0: Fib[0] = 0
val fib1: Fib[1] = 1
val fib2: Fib[2] = 1
val fib3: Fib[3] = 2 // fails to compile

Compilation output

[error] 21 |  val fib3: Fib[3] = 2
[error]    |                     ^
[error]    |                     Found:    (2 : Int)
[error]    |                     Required: (1 : Int)
[error] one error found

expectation

compiles successfully

@nicolasstucki nicolasstucki self-assigned this Mar 6, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 6, 2020
@nicolasstucki
Copy link
Contributor

The code is buggy

import scala.compiletime.ops.int._

object Test {
  type Fib[N <: Int] <: Int = N match {
    case 0 => 0
    case 1 => 1
    case _ => Fib[N - 1] + Fib[N - 2] // removed extra Fib
  }
  val fib0: Fib[0] = 0
  val fib1: Fib[1] = 1
  val fib2: Fib[2] = 1
  val fib3: Fib[3] = 2
}

@nicolasstucki nicolasstucki linked a pull request Mar 6, 2020 that will close this issue
anatoliykmetyuk added a commit that referenced this issue Mar 6, 2020
@weihsiu
Copy link
Author

weihsiu commented Mar 6, 2020

Thanks, sorry for the noise.

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.

2 participants