Skip to content

Fix #7743: Widen by-name parameter termrefs in pattern matching trans… #7776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ class PatternMatcher extends MiniPhase {
override def transformMatch(tree: Match)(implicit ctx: Context): Tree =
if (tree.isInstanceOf[InlineMatch]) tree
else {
val translated = new Translator(tree.tpe, this).translateMatch(tree)
// Widen termrefs with underlying `=> T` types. Otherwise ElimByName will produce
// inconsistent types. See i7743.scala.
// Question: Does this need to be done more systematically, not just for pattern matches?
val matchType = tree.tpe.widenSingleton match
case ExprType(rt) => rt
case rt => tree.tpe
val translated = new Translator(matchType, this).translateMatch(tree)

// check exhaustivity and unreachability
val engine = new patmat.SpaceEngine
engine.checkExhaustivity(tree)
engine.checkRedundancy(tree)

translated.ensureConforms(tree.tpe)
translated.ensureConforms(matchType)
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/pos/i7743.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def foo(x: => String) = 1 match {
case _ => x
}