Skip to content

Commit 431dc90

Browse files
authored
Merge pull request #4212 from dotty-staging/fix/impfun-pattern
Fix #4203: Don't expand implicit functions in patterns
2 parents b6dbe42 + c13400a commit 431dc90

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,7 @@ class Typer extends Namer
18211821
xtree.isTerm &&
18221822
!untpd.isImplicitClosure(xtree) &&
18231823
!ctx.mode.is(Mode.ImplicitShadowing) &&
1824+
!ctx.mode.is(Mode.Pattern) &&
18241825
!ctx.isAfterTyper)
18251826
makeImplicitFunction(xtree, ifpt)
18261827
else xtree match {
@@ -2317,6 +2318,7 @@ class Typer extends Namer
23172318
if (defn.isImplicitFunctionClass(wtp.underlyingClassRef(refinementOK = false).classSymbol) &&
23182319
!untpd.isImplicitClosure(tree) &&
23192320
!isApplyProto(pt) &&
2321+
!ctx.mode.is(Mode.Pattern) &&
23202322
!ctx.isAfterTyper) {
23212323
typr.println(i"insert apply on implicit $tree")
23222324
typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked)

tests/pos/i4203.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
case class Box[Z](unbox: Z)
2+
3+
object Test {
4+
def foo(b: Box[implicit Int => Int]): Int = b match {
5+
case Box(f) =>
6+
implicit val i: Int = 1
7+
f
8+
}
9+
}

0 commit comments

Comments
 (0)