Skip to content

Inconsistent behavior of String literal type between pattern matching and isInstanceOf #6996

@taisukeoe

Description

@taisukeoe

minimized code

Tried with dotr in Dotty compiler version 0.17.0-RC1 .

def isAType(arg: String): Unit = arg match {    
  case _ : "a" => println("This is `a` type")
  case _ => println("not `a`")
}

isAType("a")
//This is `a` type

isAType(new String("a"))
//This is `a` type

new String("a").isInstanceOf["a"]
//val res0: Boolean = false

expectation

new String("a") should not match with case _ : "a" as it doesn't with isInstanceOf.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions