From 2f42f51453ceb671d8028fabcb92fb17fb3af93c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 25 Aug 2019 17:25:34 +0200 Subject: [PATCH] Fix #7070: Allow for inserted applies when checking extension methods --- .../src/dotty/tools/dotc/typer/Applications.scala | 12 ++++++------ tests/pos/i7070.scala | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 tests/pos/i7070.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 15deb9ac698c..49a124823534 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1883,12 +1883,12 @@ trait Applications extends Compatibility { self: Typer with Dynamic => val app = typed(untpd.Apply(core, untpd.TypedSplice(receiver) :: Nil), pt1, ctx.typerState.ownedVars)( ctx.addMode(Mode.SynthesizeExtMethodReceiver)) - val appSym = - app match { - case Inlined(call, _, _) => call.symbol - case _ => app.symbol - } - if (!appSym.is(Extension)) + def isExtension(tree: Tree): Boolean = methPart(tree) match { + case Inlined(call, _, _) => isExtension(call) + case tree @ Select(qual, nme.apply) => tree.symbol.is(Extension) || isExtension(qual) + case tree => tree.symbol.is(Extension) + } + if (!isExtension(app)) ctx.error(em"not an extension method: $methodRef", receiver.sourcePos) app } diff --git a/tests/pos/i7070.scala b/tests/pos/i7070.scala new file mode 100644 index 000000000000..f5f01d3145bf --- /dev/null +++ b/tests/pos/i7070.scala @@ -0,0 +1,10 @@ +object Test { + + class C + + def (str: String) foo: given C => Int = ??? + + given as C = ??? + + val strFoo = "".foo +} \ No newline at end of file