Skip to content

Difference between case _ and case Any in match types #9171

Closed
@OlivierBlanvillain

Description

@OlivierBlanvillain

While playing with i8449.scala, I noticed that there is a difference between case _ and case Any in match types:

object Test {
  type Fib[N <: Int] <: Int = N match {
    case 0 => 0
    case 1 => 1
    case Any => Fib[N - 1] + Fib[N - 2]
  }
  val fib2: Fib[2] = 1
}
-- [E007] Type Mismatch Error: /home/olivier/workspace/dotty/tests/pos/i8449.scala:12:21       
12 |  val fib2: Fib[2] = 1
   |                     ^
   |                   Found:    (1 : Int)
   |                   Required: LazyRef(Test.Fib[(2 : Int) - (1 : Int)]) +                    
   |                     LazyRef(Test.Fib[(2 : Int) - (2 : Int)])                              

(This test compiles fine with case _ inatead of case Any).

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions