Skip to content

Commit 8201ceb

Browse files
nicolasstuckiWojciechMazur
authored andcommitted
Optimize FunctionNOf.unapply
[Cherry-picked bbd8d81]
1 parent 0cad37b commit 8201ceb

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,13 +1138,10 @@ class Definitions {
11381138
/** Matches a (possibly aliased) `FunctionN[...]` or `ContextFunctionN[...]`.
11391139
* Extracts the list of function argument types, the result type and whether function is contextual.
11401140
*/
1141-
def unapply(tpe: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
1142-
val tsym = tpe.typeSymbol
1143-
if isFunctionSymbol(tsym) && tpe.isRef(tsym) then
1144-
val targs = tpe.argInfos
1145-
if (targs.isEmpty) None
1146-
else Some(targs.init, targs.last, tsym.name.isContextFunction)
1147-
else None
1141+
def unapply(tpe: AppliedType)(using Context): Option[(List[Type], Type, Boolean)] = {
1142+
val targs = tpe.args
1143+
if targs.isEmpty || !isFunctionNType(tpe) then None
1144+
else Some(targs.init, targs.last, tpe.typeSymbol.name.isContextFunction)
11481145
}
11491146
}
11501147

0 commit comments

Comments
 (0)