@@ -248,6 +248,9 @@ trait Applications extends Compatibility {
248
248
/** The type of typed arguments: either tpd.Tree or Type */
249
249
type TypedArg
250
250
251
+ /** The kind of application that gets typed */
252
+ def applyKind : ApplyKind
253
+
251
254
/** Given an original argument and the type of the corresponding formal
252
255
* parameter, produce a typed argument.
253
256
*/
@@ -609,7 +612,14 @@ trait Applications extends Compatibility {
609
612
610
613
case nil =>
611
614
args match {
612
- case arg :: args1 => fail(s " too many arguments for $methString" , arg)
615
+ case arg :: args1 =>
616
+ val msg = arg match
617
+ case untpd.Tuple (Nil )
618
+ if applyKind == ApplyKind .InfixUnit && funType.widen.isNullaryMethod =>
619
+ i " can't supply unit value with infix notation because nullary $methString takes no arguments; use dotted invocation instead: (...). ${methRef.name}() "
620
+ case _ =>
621
+ i " too many arguments for $methString"
622
+ fail(msg, arg)
613
623
case nil =>
614
624
}
615
625
}
@@ -624,6 +634,8 @@ trait Applications extends Compatibility {
624
634
type TypedArg = Arg
625
635
type Result = Unit
626
636
637
+ def applyKind = ApplyKind .Regular
638
+
627
639
protected def argOK (arg : TypedArg , formal : Type ): Boolean = argType(arg, formal) match {
628
640
case ref : TermRef if ref.denot.isOverloaded =>
629
641
// in this case we could not resolve overloading because no alternative
@@ -687,7 +699,8 @@ trait Applications extends Compatibility {
687
699
* types of arguments are either known or unknown.
688
700
*/
689
701
abstract class TypedApply [T >: Untyped ](
690
- app : untpd.Apply , fun : Tree , methRef : TermRef , args : List [Trees .Tree [T ]], resultType : Type )(using Context )
702
+ app : untpd.Apply , fun : Tree , methRef : TermRef , args : List [Trees .Tree [T ]], resultType : Type ,
703
+ override val applyKind : ApplyKind )(using Context )
691
704
extends Application (methRef, fun.tpe, args, resultType) {
692
705
type TypedArg = Tree
693
706
def isVarArg (arg : Trees .Tree [T ]): Boolean = untpd.isWildcardStarArg(arg)
@@ -795,16 +808,20 @@ trait Applications extends Compatibility {
795
808
}
796
809
797
810
/** Subclass of Application for type checking an Apply node with untyped arguments. */
798
- class ApplyToUntyped (app : untpd.Apply , fun : Tree , methRef : TermRef , proto : FunProto , resultType : Type )(using Context )
799
- extends TypedApply (app, fun, methRef, proto.args, resultType) {
811
+ class ApplyToUntyped (
812
+ app : untpd.Apply , fun : Tree , methRef : TermRef , proto : FunProto ,
813
+ resultType : Type )(using Context )
814
+ extends TypedApply (app, fun, methRef, proto.args, resultType, proto.applyKind) {
800
815
def typedArg (arg : untpd.Tree , formal : Type ): TypedArg = proto.typedArg(arg, formal)
801
816
def treeToArg (arg : Tree ): untpd.Tree = untpd.TypedSplice (arg)
802
817
def typeOfArg (arg : untpd.Tree ): Type = proto.typeOfArg(arg)
803
818
}
804
819
805
820
/** Subclass of Application for type checking an Apply node with typed arguments. */
806
- class ApplyToTyped (app : untpd.Apply , fun : Tree , methRef : TermRef , args : List [Tree ], resultType : Type )(using Context )
807
- extends TypedApply (app, fun, methRef, args, resultType) {
821
+ class ApplyToTyped (
822
+ app : untpd.Apply , fun : Tree , methRef : TermRef , args : List [Tree ],
823
+ resultType : Type , applyKind : ApplyKind )(using Context )
824
+ extends TypedApply (app, fun, methRef, args, resultType, applyKind) {
808
825
def typedArg (arg : Tree , formal : Type ): TypedArg = arg
809
826
def treeToArg (arg : Tree ): Tree = arg
810
827
def typeOfArg (arg : Tree ): Type = arg.tpe
@@ -840,7 +857,8 @@ trait Applications extends Compatibility {
840
857
def typedApply (tree : untpd.Apply , pt : Type )(using Context ): Tree = {
841
858
842
859
def realApply (using Context ): Tree = {
843
- val originalProto = new FunProto (tree.args, IgnoredProto (pt))(this , tree.isUsingApply)(using argCtx(tree))
860
+ val originalProto =
861
+ new FunProto (tree.args, IgnoredProto (pt))(this , tree.applyKind)(using argCtx(tree))
844
862
record(" typedApply" )
845
863
val fun1 = typedFunPart(tree.fun, originalProto)
846
864
@@ -998,7 +1016,7 @@ trait Applications extends Compatibility {
998
1016
def ApplyTo (app : untpd.Apply , fun : tpd.Tree , methRef : TermRef , proto : FunProto , resultType : Type )(using Context ): tpd.Tree =
999
1017
val typer = ctx.typer
1000
1018
if (proto.allArgTypesAreCurrent())
1001
- typer.ApplyToTyped (app, fun, methRef, proto.typedArgs(), resultType).result
1019
+ typer.ApplyToTyped (app, fun, methRef, proto.typedArgs(), resultType, proto.applyKind ).result
1002
1020
else
1003
1021
typer.ApplyToUntyped (app, fun, methRef, proto, resultType)(
1004
1022
using fun.nullableInArgContext(using argCtx(app))).result
@@ -1655,7 +1673,7 @@ trait Applications extends Compatibility {
1655
1673
def resolve (alts : List [TermRef ]): List [TermRef ] =
1656
1674
pt match
1657
1675
case pt : FunProto =>
1658
- if pt.isUsingApply then
1676
+ if pt.applyKind == ApplyKind . Using then
1659
1677
val alts0 = alts.filterConserve { alt =>
1660
1678
val mt = alt.widen.stripPoly
1661
1679
mt.isImplicitMethod || mt.isContextualMethod
0 commit comments