See https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala#L76 for another duplication site. Looking at it again, it should probably use mkCastPreservingAnnotations and move to TreeGen.