Skip to content

Commit 0957925

Browse files
committed
canApplyImplicits is false if not using
1 parent b44f1a2 commit 0957925

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ import Constants.{Constant, IntTag}
3434
import Denotations.SingleDenotation
3535
import annotation.threadUnsafe
3636

37-
import scala.util.control.NonFatal
38-
import dotty.tools.dotc.inlines.Inlines
3937
import scala.annotation.tailrec
38+
import scala.util.control.NonFatal
4039
import dotty.tools.dotc.cc.isRetains
40+
import dotty.tools.dotc.inlines.Inlines
41+
import dotty.tools.dotc.util.chaining.*
4142

4243
object Applications {
4344
import tpd.*
@@ -607,7 +608,7 @@ trait Applications extends Compatibility {
607608
fail(TypeMismatch(methType.resultType, resultType, None))
608609

609610
// match all arguments with corresponding formal parameters
610-
if success then matchArgs(orderedArgs, methType.paramInfos, n=0)
611+
if success then matchArgs(orderedArgs, methType.paramInfos, n = 0)
611612
case _ =>
612613
if (methType.isError) ok = false
613614
else fail(em"$methString does not take parameters")
@@ -765,20 +766,18 @@ trait Applications extends Compatibility {
765766
}
766767
else defaultArgument(normalizedFun, n, testOnly)
767768

768-
// a bug allowed empty parens to expand to implicit args, offer rewrite only on migration
769+
// a bug allowed empty parens to expand to implicit args: fail empty args for rewrite on migration
769770
def canSupplyImplicits = methodType.isImplicitMethod
770-
&& (applyKind == ApplyKind.Using || {
771-
if args1.isEmpty then
771+
&& (applyKind == ApplyKind.Using || false.tap: _ =>
772+
if Application.this.args.isEmpty then
772773
fail(MissingImplicitParameterInEmptyArguments(methodType.paramNames(n), methString))
773-
true
774-
})
775-
&& ctx.mode.is(Mode.ImplicitsEnabled)
774+
)
776775

777776
if !defaultArg.isEmpty then
778777
defaultArg.tpe.widen match
779778
case _: MethodOrPoly if testOnly => matchArgs(args1, formals1, n + 1)
780779
case _ => matchArgs(args1, addTyped(treeToArg(defaultArg)), n + 1)
781-
else if methodType.isContextualMethod && ctx.mode.is(Mode.ImplicitsEnabled) || canSupplyImplicits then
780+
else if (methodType.isContextualMethod || canSupplyImplicits) && ctx.mode.is(Mode.ImplicitsEnabled) then
782781
val implicitArg = implicitArgTree(formal, appPos.span)
783782
matchArgs(args1, addTyped(treeToArg(implicitArg)), n + 1)
784783
else
@@ -1198,8 +1197,7 @@ trait Applications extends Compatibility {
11981197
retry = true
11991198
rewrites.Rewrites.patch(tree.span.withStart(tree.span.point), "") // f() -> f
12001199
Diagnostic.Warning(err.msg, err.pos)
1201-
else
1202-
err
1200+
else err
12031201
case _ => err
12041202
case dia => dia
12051203
retry

tests/neg/i22439.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
7 | f() // error f() missing arg
33
| ^^^
44
| missing argument for parameter i of method f: (implicit i: Int, j: Int): Int
5+
| This code can be rewritten automatically under -rewrite -source 3.7-migration.
6+
|
7+
| longer explanation available when compiling with `-explain`
58
-- [E050] Type Error: tests/neg/i22439.scala:8:2 -----------------------------------------------------------------------
69
8 | g() // error g(given_Int, given_Int)() doesn't take more params
710
| ^
@@ -24,3 +27,6 @@
2427
21 | val (ws, zs) = vs.unzip() // error!
2528
| ^^^^^^^^^^
2629
|missing argument for parameter asPair of method unzip in trait StrictOptimizedIterableOps: (implicit asPair: ((Int, Int)) => (A1, A2)): (List[A1], List[A2])
30+
|This code can be rewritten automatically under -rewrite -source 3.7-migration.
31+
|
32+
| longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)