Skip to content

Commit

Permalink
Use unreachable for match cases that are known to be unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jan 5, 2021
1 parent 872082e commit 2623ed0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ object desugar {
paramss.mapConserve {
case TypeDefs(tparams) => tparams.mapConserve(mapTypeParam)
case ValDefs(vparams) => vparams.mapConserve(mapTermParam)
case _ => ??? // impossible
case _ => unreachable()
}

/** 1. Expand context bounds to evidence params. E.g.,
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
paramss.map {
case TypeSymbols(params) => params.map(param => TypeDef(param).withSpan(param.span))
case TermSymbols(params) => params.map(param => ValDef(param).withSpan(param.span))
case _ => ???
case _ => unreachable()
},
TypeTree(resultType),
rhs),
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/init/Potentials.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dotty.tools.dotc
package dotty.tools
package dotc
package transform
package init

Expand Down Expand Up @@ -101,7 +102,7 @@ object Potentials {
case Some((parentCls, pots)) =>
val rebased: Potentials = outerPots.flatMap { Potentials.asSeenFrom(pots, _) }
resolveOuter(parentCls, rebased, cls)
case None => ??? // impossible
case None => unreachable()
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ package object tools {
type WrappedResult[T] = resultWrapper.WrappedResult[T]
def WrappedResult[T](x: T) = resultWrapper.wrap(x)
def result[T](using x: WrappedResult[T]): T = resultWrapper.unwrap(x)

def unreachable(x: Any = "<< this case was declared unreachable >>"): Nothing =
throw new MatchError(x)
}

0 comments on commit 2623ed0

Please sign in to comment.