Skip to content

Commit d9d3bea

Browse files
committed
Address review
1 parent 276cf27 commit d9d3bea

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,15 +1009,18 @@ object desugar {
10091009
* IrrefutableGenFrom: sel with attachment `CheckIrrefutable -> checkMode`
10101010
*/
10111011
def makeSelector(sel: Tree, checkMode: MatchCheck)(using Context): Tree =
1012-
if (checkMode == MatchCheck.Exhaustive) sel
1013-
else {
1014-
if (checkMode == MatchCheck.None)
1015-
Annotated(sel, New(ref(defn.UncheckedAnnot.typeRef)))
1016-
else
1017-
// TODO: use `pushAttachment` and investigate duplicate attachment
1018-
sel.withAttachment(CheckIrrefutable, checkMode)
1019-
sel
1020-
}
1012+
checkMode match
1013+
case MatchCheck.None =>
1014+
Annotated(sel, New(ref(defn.UncheckedAnnot.typeRef)))
1015+
1016+
case MatchCheck.Exhaustive =>
1017+
sel
1018+
1019+
case MatchCheck.IrrefutablePatDef | MatchCheck.IrrefutableGenFrom =>
1020+
// TODO: use `pushAttachment` and investigate duplicate attachment
1021+
sel.withAttachment(CheckIrrefutable, checkMode)
1022+
sel
1023+
end match
10211024

10221025
/** If `pat` is a variable pattern,
10231026
*

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ trait Checking {
671671
report.error(ex"$cls cannot be instantiated since it${rstatus.msg}", pos)
672672
}
673673

674-
/** Check that pattern `pat` is irrefutable for scrutinee tye `sel.tpe`.
674+
/** Check that pattern `pat` is irrefutable for scrutinee type `sel.tpe`.
675675
* This means `sel` is either marked @unchecked or `sel.tpe` conforms to the
676676
* pattern's type. If pattern is an UnApply, do the check recursively.
677677
*/

docs/docs/reference/changed-features/pattern-bindings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ want to decompose it like this:
2525
```scala
2626
val first :: rest = elems // error
2727
```
28-
This works in Scala 2. In fact it is a typical use case for Scala 2's rules. But in Scala 3.1 it will give a type error. One can avoid the error by marking the rhs with an `@unchecked` annotation:
28+
This works in Scala 2. In fact it is a typical use case for Scala 2's rules. But in Scala 3.1 it will give a type error. One can avoid the error by marking the right-hand side with an `@unchecked` annotation:
2929
```scala
3030
val first :: rest = elems: @unchecked // OK
3131
```

0 commit comments

Comments
 (0)