Skip to content

Commit

Permalink
Optimize FunctionNOf.unapply
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Aug 30, 2023
1 parent d78c157 commit bbd8d81
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1136,13 +1136,10 @@ class Definitions {
/** Matches a (possibly aliased) `FunctionN[...]` or `ContextFunctionN[...]`.
* Extracts the list of function argument types, the result type and whether function is contextual.
*/
def unapply(tpe: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
val tsym = tpe.typeSymbol
if isFunctionSymbol(tsym) && tpe.isRef(tsym) then
val targs = tpe.argInfos
if (targs.isEmpty) None
else Some(targs.init, targs.last, tsym.name.isContextFunction)
else None
def unapply(tpe: AppliedType)(using Context): Option[(List[Type], Type, Boolean)] = {
val targs = tpe.args
if targs.isEmpty || !isFunctionNType(tpe) then None
else Some(targs.init, targs.last, tpe.typeSymbol.name.isContextFunction)
}
}

Expand Down

0 comments on commit bbd8d81

Please sign in to comment.