Skip to content

Commit 2623ed0

Browse files
committed
Use unreachable for match cases that are known to be unreachable
1 parent 872082e commit 2623ed0

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ object desugar {
200200
paramss.mapConserve {
201201
case TypeDefs(tparams) => tparams.mapConserve(mapTypeParam)
202202
case ValDefs(vparams) => vparams.mapConserve(mapTermParam)
203-
case _ => ??? // impossible
203+
case _ => unreachable()
204204
}
205205

206206
/** 1. Expand context bounds to evidence params. E.g.,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
215215
paramss.map {
216216
case TypeSymbols(params) => params.map(param => TypeDef(param).withSpan(param.span))
217217
case TermSymbols(params) => params.map(param => ValDef(param).withSpan(param.span))
218-
case _ => ???
218+
case _ => unreachable()
219219
},
220220
TypeTree(resultType),
221221
rhs),

compiler/src/dotty/tools/dotc/transform/init/Potentials.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package transform
34
package init
45

@@ -101,7 +102,7 @@ object Potentials {
101102
case Some((parentCls, pots)) =>
102103
val rebased: Potentials = outerPots.flatMap { Potentials.asSeenFrom(pots, _) }
103104
resolveOuter(parentCls, rebased, cls)
104-
case None => ??? // impossible
105+
case None => unreachable()
105106
}
106107
}
107108
}

compiler/src/dotty/tools/package.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ package object tools {
5050
type WrappedResult[T] = resultWrapper.WrappedResult[T]
5151
def WrappedResult[T](x: T) = resultWrapper.wrap(x)
5252
def result[T](using x: WrappedResult[T]): T = resultWrapper.unwrap(x)
53+
54+
def unreachable(x: Any = "<< this case was declared unreachable >>"): Nothing =
55+
throw new MatchError(x)
5356
}

0 commit comments

Comments
 (0)