Skip to content

Commit 1d585f1

Browse files
committed
Use hasNamedArgs instead of repeating test inline.
1 parent 356e59c commit 1d585f1

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
215215
case _ => false
216216
}
217217

218+
/** Does this list contain a named argument tree? */
219+
def hasNamedArg(args: List[Any]) = args exists isNamedArg
220+
val isNamedArg = (arg: Any) => arg.isInstanceOf[Trees.NamedArg[_]]
221+
218222
/** Is this pattern node a catch-all (wildcard or variable) pattern? */
219223
def isDefaultCase(cdef: CaseDef) = cdef match {
220224
case CaseDef(pat, EmptyTree, _) => isWildcardArg(pat)

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import language.implicitConversions
2929

3030
object Applications {
3131
import tpd._
32-
private val isNamedArg = (arg: Any) => arg.isInstanceOf[Trees.NamedArg[_]]
33-
def hasNamedArg(args: List[Any]) = args exists isNamedArg
3432

3533
def extractorMemberType(tp: Type, name: Name, errorPos: Position = NoPosition)(implicit ctx:Context) = {
3634
val ref = tp.member(name).suchThat(_.info.isParameterless)
@@ -1061,10 +1059,8 @@ trait Applications extends Compatibility { self: Typer =>
10611059

10621060
def narrowByShapes(alts: List[TermRef]): List[TermRef] = {
10631061
if (normArgs exists (_.isInstanceOf[untpd.Function]))
1064-
if (args exists (_.isInstanceOf[Trees.NamedArg[_]]))
1065-
narrowByTrees(alts, args map treeShape, resultType)
1066-
else
1067-
narrowByTypes(alts, normArgs map typeShape, resultType)
1062+
if (hasNamedArg(args)) narrowByTrees(alts, args map treeShape, resultType)
1063+
else narrowByTypes(alts, normArgs map typeShape, resultType)
10681064
else
10691065
alts
10701066
}

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ trait TypeAssigner {
395395
errorType(s"named and positional type arguments may not be mixed", arg.pos)
396396
}
397397
val ownType =
398-
if (args.head.isInstanceOf[NamedArg]) (tycon.tpe /: args)(refineNamed)
398+
if (hasNamedArg(args)) (tycon.tpe /: args)(refineNamed)
399399
else if (sameLength(tparams, args)) tycon.tpe.appliedTo(args.tpes)
400400
else errorType(d"wrong number of type arguments for ${tycon.tpe}, should be ${tparams.length}", tree.pos)
401401
tree.withType(ownType)

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import SymDenotations._
1717
import Annotations._
1818
import Names._
1919
import NameOps._
20+
import Applications._
2021
import Flags._
2122
import Decorators._
2223
import ErrorReporting._
@@ -892,7 +893,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
892893
else {
893894
var args = tree.args
894895
val args1 =
895-
if (args.head.isInstanceOf[untpd.NamedArg])
896+
if (hasNamedArg(args))
896897
for (arg @ NamedArg(id, argtpt) <- args) yield {
897898
val argtpt1 = typedType(argtpt)
898899
cpy.NamedArg(arg)(id, argtpt1).withType(argtpt1.tpe)

0 commit comments

Comments
 (0)