From a083a7a2cb37ee2b2ea2c7f33657666ef87dc326 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 30 Aug 2023 16:36:55 +0200 Subject: [PATCH] Simplify `defn.FunctionOf.unapply` --- .../src/dotty/tools/dotc/cc/CheckCaptures.scala | 2 +- .../src/dotty/tools/dotc/core/Definitions.scala | 13 +++++-------- .../src/dotty/tools/dotc/transform/Recheck.scala | 2 +- .../src/dotty/tools/dotc/typer/Applications.scala | 5 +---- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala index d5bd8522ca92..e35c7eedaeab 100644 --- a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala +++ b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala @@ -484,7 +484,7 @@ class CheckCaptures extends Recheck, SymTransformer: else if meth == defn.Caps_unsafeUnbox then mapArgUsing(_.forceBoxStatus(false)) else if meth == defn.Caps_unsafeBoxFunArg then - def forceBox(tp: Type): Type = tp match + def forceBox(tp: Type): Type = tp.strippedDealias match case defn.FunctionOf(paramtpe :: Nil, restpe, isContextual) => defn.FunctionOf(paramtpe.forceBoxStatus(true) :: Nil, restpe, isContextual) case tp @ RefinedType(parent, rname, rinfo: MethodType) => diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 22a49a760e57..3d7a711c8f58 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1116,16 +1116,13 @@ class Definitions { else FunctionType(args.length, isContextual).appliedTo(args ::: resultType :: Nil) def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean)] = { - ft.dealias match + ft match case PolyFunctionOf(mt: MethodType) => Some(mt.paramInfos, mt.resType, mt.isContextualMethod) - case dft => - val tsym = dft.typeSymbol - if isFunctionSymbol(tsym) && ft.isRef(tsym) then - val targs = dft.argInfos - if (targs.isEmpty) None - else Some(targs.init, targs.last, tsym.name.isContextFunction) - else None + case AppliedType(parent, targs) if isFunctionNType(ft) => + Some(targs.init, targs.last, ft.typeSymbol.name.isContextFunction) + case _ => + None } } diff --git a/compiler/src/dotty/tools/dotc/transform/Recheck.scala b/compiler/src/dotty/tools/dotc/transform/Recheck.scala index 2456e4011367..5913a4f35939 100644 --- a/compiler/src/dotty/tools/dotc/transform/Recheck.scala +++ b/compiler/src/dotty/tools/dotc/transform/Recheck.scala @@ -115,7 +115,7 @@ object Recheck: * - in function and method parameter types * - under annotations */ - def normalizeByName(tp: Type)(using Context): Type = tp match + def normalizeByName(tp: Type)(using Context): Type = tp.dealias match case tp: ExprType => mapExprType(tp) case tp: PolyType => diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 921e3ca86fe4..381974b81ca0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1990,10 +1990,7 @@ trait Applications extends Compatibility { // the arity of that function, otherise -1. def paramCount(ref: TermRef) = val formals = ref.widen.firstParamTypes - if formals.length > idx then - formals(idx) match - case defn.FunctionOf(args, _, _) => args.length - case _ => -1 + if formals.length > idx then defn.functionArity(formals(idx)) else -1 val numArgs = args.length