Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
else tree1
}

def typedPatternLiteral(tree: untpd.Literal, pt: Type)(using Context): Tree = {
val tree1 = typedLiteral(tree)

if (!(tree1.tpe <:< pt))
report.error(TypeMismatch(tree1.tpe, pt, Some(tree1)), tree.srcPos)

tree1
}

def typedNew(tree: untpd.New, pt: Type)(using Context): Tree =
tree.tpt match {
case templ: untpd.Template =>
Expand Down Expand Up @@ -3675,7 +3684,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if (ctx.mode is Mode.Pattern) typedUnApply(tree, pt) else typedApply(tree, pt)
case tree: untpd.This => typedThis(tree)
case tree: untpd.Number => typedNumber(tree, pt)
case tree: untpd.Literal => typedLiteral(tree)
case tree: untpd.Literal =>
if (ctx.mode is Mode.Pattern) typedPatternLiteral(tree, pt) else typedLiteral(tree)
case tree: untpd.New => typedNew(tree, pt)
case tree: untpd.Typed => typedTyped(tree, pt)
case tree: untpd.NamedArg => typedNamedArg(tree, pt)
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/bigint-literal-pattern.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test:
def bad: Unit =
(BigInt(1): BigInt) match
case 1 => () // error: .*BigInt
case _ => ()
Loading