Skip to content

Commit cfa8e9f

Browse files
committed
canApplyImplicits is false if not using
1 parent 66539de commit cfa8e9f

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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

+8-10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import annotation.threadUnsafe
3636

3737
import scala.util.control.NonFatal
3838
import dotty.tools.dotc.inlines.Inlines
39+
import dotty.tools.dotc.util.chaining.*
3940

4041
object Applications {
4142
import tpd.*
@@ -602,7 +603,7 @@ trait Applications extends Compatibility {
602603
fail(TypeMismatch(methType.resultType, resultType, None))
603604

604605
// match all arguments with corresponding formal parameters
605-
if success then matchArgs(orderedArgs, methType.paramInfos, n=0)
606+
if success then matchArgs(orderedArgs, methType.paramInfos, n = 0)
606607
case _ =>
607608
if (methType.isError) ok = false
608609
else fail(em"$methString does not take parameters")
@@ -757,20 +758,18 @@ trait Applications extends Compatibility {
757758
}
758759
else defaultArgument(normalizedFun, n, testOnly)
759760

760-
// a bug allowed empty parens to expand to implicit args, offer rewrite only on migration
761+
// a bug allowed empty parens to expand to implicit args: fail empty args for rewrite on migration
761762
def canSupplyImplicits = methodType.isImplicitMethod
762-
&& (applyKind == ApplyKind.Using || {
763-
if args1.isEmpty then
763+
&& (applyKind == ApplyKind.Using || false.tap: _ =>
764+
if Application.this.args.isEmpty then
764765
fail(MissingImplicitParameterInEmptyArguments(methodType.paramNames(n), methString))
765-
true
766-
})
767-
&& ctx.mode.is(Mode.ImplicitsEnabled)
766+
)
768767

769768
if !defaultArg.isEmpty then
770769
defaultArg.tpe.widen match
771770
case _: MethodOrPoly if testOnly => matchArgs(args1, formals1, n + 1)
772771
case _ => matchArgs(args1, addTyped(treeToArg(defaultArg)), n + 1)
773-
else if methodType.isContextualMethod && ctx.mode.is(Mode.ImplicitsEnabled) || canSupplyImplicits then
772+
else if (methodType.isContextualMethod || canSupplyImplicits) && ctx.mode.is(Mode.ImplicitsEnabled) then
774773
val implicitArg = implicitArgTree(formal, appPos.span)
775774
matchArgs(args1, addTyped(treeToArg(implicitArg)), n + 1)
776775
else
@@ -1190,8 +1189,7 @@ trait Applications extends Compatibility {
11901189
retry = true
11911190
rewrites.Rewrites.patch(tree.span.withStart(tree.span.point), "") // f() -> f
11921191
Diagnostic.Warning(err.msg, err.pos)
1193-
else
1194-
err
1192+
else err
11951193
case _ => err
11961194
case dia => dia
11971195
retry

tests/neg/i22439.check

+6
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)