From f45857967e563f2d0decc883b99ac64a1ac20f92 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 30 Jun 2025 17:14:31 +0200 Subject: [PATCH 1/2] Backport new ErrorMessageID and messages --- .../src/dotty/tools/dotc/reporting/ErrorMessageID.scala | 1 + compiler/src/dotty/tools/dotc/reporting/messages.scala | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala index 896e00a46053..5ab4c7eb0b28 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala @@ -228,6 +228,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe case OnlyFullyDependentAppliedConstructorTypeID // errorNumber: 212 case PointlessAppliedConstructorTypeID // errorNumber: 213 case IllegalContextBoundsID // errorNumber: 214 + case NamedPatternNotApplicableID // errorNumber: 215 def errorNumber = ordinal - 1 diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index d83558475741..8732d2333620 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -3262,4 +3262,8 @@ final class IllegalContextBounds(using Context) extends SyntaxMsg(IllegalContext override protected def explain(using Context): String = "" -end IllegalContextBounds +final class NamedPatternNotApplicable(selectorType: Type)(using Context) extends PatternMatchMsg(NamedPatternNotApplicableID): + override protected def msg(using Context): String = + i"Named patterns cannot be used with $selectorType, because it is not a named tuple or case class" + + override protected def explain(using Context): String = "" \ No newline at end of file From 17a89d4fe1a538e8ef575f40649db33677638c84 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 30 Jun 2025 17:15:35 +0200 Subject: [PATCH 2/2] Improve error message when trying to use named extraction, when not matching case class or named tuple. Co-authored-by: nmcb Co-authored-by: jan-pieter Co-authored-by: wwbakker Co-authored-by: thijsnissen Co-authored-by: RoccoMathijn [Cherry-picked 6aaff88cbb748fe67efe0aa89f0eba6ab8e07335][modified]