File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -32,14 +32,20 @@ class PatternMatcher extends MiniPhase {
3232 override def transformMatch (tree : Match )(implicit ctx : Context ): Tree =
3333 if (tree.isInstanceOf [InlineMatch ]) tree
3434 else {
35- val translated = new Translator (tree.tpe, this ).translateMatch(tree)
35+ // Widen termrefs with underlying `=> T` types. Otherwise ElimByName will produce
36+ // inconsistent types. See i7743.scala.
37+ // Question: Does this need to be done more systematically, not just for pattern matches?
38+ val matchType = tree.tpe.widenSingleton match
39+ case ExprType (rt) => rt
40+ case rt => tree.tpe
41+ val translated = new Translator (matchType, this ).translateMatch(tree)
3642
3743 // check exhaustivity and unreachability
3844 val engine = new patmat.SpaceEngine
3945 engine.checkExhaustivity(tree)
4046 engine.checkRedundancy(tree)
4147
42- translated.ensureConforms(tree.tpe )
48+ translated.ensureConforms(matchType )
4349 }
4450}
4551
Original file line number Diff line number Diff line change 1+ def foo (x : => String ) = 1 match {
2+ case _ => x
3+ }
You can’t perform that action at this time.
0 commit comments