@@ -248,6 +248,9 @@ trait Applications extends Compatibility {
248248 /** The type of typed arguments: either tpd.Tree or Type */
249249 type TypedArg
250250
251+ /** The kind of application that gets typed */
252+ def applyKind : ApplyKind
253+
251254 /** Given an original argument and the type of the corresponding formal
252255 * parameter, produce a typed argument.
253256 */
@@ -609,7 +612,14 @@ trait Applications extends Compatibility {
609612
610613 case nil =>
611614 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)
613623 case nil =>
614624 }
615625 }
@@ -624,6 +634,8 @@ trait Applications extends Compatibility {
624634 type TypedArg = Arg
625635 type Result = Unit
626636
637+ def applyKind = ApplyKind .Regular
638+
627639 protected def argOK (arg : TypedArg , formal : Type ): Boolean = argType(arg, formal) match {
628640 case ref : TermRef if ref.denot.isOverloaded =>
629641 // in this case we could not resolve overloading because no alternative
@@ -687,7 +699,8 @@ trait Applications extends Compatibility {
687699 * types of arguments are either known or unknown.
688700 */
689701 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 )
691704 extends Application (methRef, fun.tpe, args, resultType) {
692705 type TypedArg = Tree
693706 def isVarArg (arg : Trees .Tree [T ]): Boolean = untpd.isWildcardStarArg(arg)
@@ -795,16 +808,20 @@ trait Applications extends Compatibility {
795808 }
796809
797810 /** 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) {
800815 def typedArg (arg : untpd.Tree , formal : Type ): TypedArg = proto.typedArg(arg, formal)
801816 def treeToArg (arg : Tree ): untpd.Tree = untpd.TypedSplice (arg)
802817 def typeOfArg (arg : untpd.Tree ): Type = proto.typeOfArg(arg)
803818 }
804819
805820 /** 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) {
808825 def typedArg (arg : Tree , formal : Type ): TypedArg = arg
809826 def treeToArg (arg : Tree ): Tree = arg
810827 def typeOfArg (arg : Tree ): Type = arg.tpe
@@ -840,7 +857,8 @@ trait Applications extends Compatibility {
840857 def typedApply (tree : untpd.Apply , pt : Type )(using Context ): Tree = {
841858
842859 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))
844862 record(" typedApply" )
845863 val fun1 = typedFunPart(tree.fun, originalProto)
846864
@@ -998,7 +1016,7 @@ trait Applications extends Compatibility {
9981016 def ApplyTo (app : untpd.Apply , fun : tpd.Tree , methRef : TermRef , proto : FunProto , resultType : Type )(using Context ): tpd.Tree =
9991017 val typer = ctx.typer
10001018 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
10021020 else
10031021 typer.ApplyToUntyped (app, fun, methRef, proto, resultType)(
10041022 using fun.nullableInArgContext(using argCtx(app))).result
@@ -1655,7 +1673,7 @@ trait Applications extends Compatibility {
16551673 def resolve (alts : List [TermRef ]): List [TermRef ] =
16561674 pt match
16571675 case pt : FunProto =>
1658- if pt.isUsingApply then
1676+ if pt.applyKind == ApplyKind . Using then
16591677 val alts0 = alts.filterConserve { alt =>
16601678 val mt = alt.widen.stripPoly
16611679 mt.isImplicitMethod || mt.isContextualMethod
0 commit comments