From c13400a889276f540c35f5509d344514e05e5704 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 29 Mar 2018 15:34:59 +0200 Subject: [PATCH] Fix #4203: Don't expand implicit functions in patterns --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 ++ tests/pos/i4203.scala | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/pos/i4203.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 954bd38ec216..431721dc44e6 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1821,6 +1821,7 @@ class Typer extends Namer xtree.isTerm && !untpd.isImplicitClosure(xtree) && !ctx.mode.is(Mode.ImplicitShadowing) && + !ctx.mode.is(Mode.Pattern) && !ctx.isAfterTyper) makeImplicitFunction(xtree, ifpt) else xtree match { @@ -2317,6 +2318,7 @@ class Typer extends Namer if (defn.isImplicitFunctionClass(wtp.underlyingClassRef(refinementOK = false).classSymbol) && !untpd.isImplicitClosure(tree) && !isApplyProto(pt) && + !ctx.mode.is(Mode.Pattern) && !ctx.isAfterTyper) { typr.println(i"insert apply on implicit $tree") typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked) diff --git a/tests/pos/i4203.scala b/tests/pos/i4203.scala new file mode 100644 index 000000000000..3549237bff2a --- /dev/null +++ b/tests/pos/i4203.scala @@ -0,0 +1,9 @@ +case class Box[Z](unbox: Z) + +object Test { + def foo(b: Box[implicit Int => Int]): Int = b match { + case Box(f) => + implicit val i: Int = 1 + f + } +}