Skip to content

Commit a083a7a

Browse files
committed
Simplify defn.FunctionOf.unapply
1 parent a37dac6 commit a083a7a

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class CheckCaptures extends Recheck, SymTransformer:
484484
else if meth == defn.Caps_unsafeUnbox then
485485
mapArgUsing(_.forceBoxStatus(false))
486486
else if meth == defn.Caps_unsafeBoxFunArg then
487-
def forceBox(tp: Type): Type = tp match
487+
def forceBox(tp: Type): Type = tp.strippedDealias match
488488
case defn.FunctionOf(paramtpe :: Nil, restpe, isContextual) =>
489489
defn.FunctionOf(paramtpe.forceBoxStatus(true) :: Nil, restpe, isContextual)
490490
case tp @ RefinedType(parent, rname, rinfo: MethodType) =>

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,16 +1116,13 @@ class Definitions {
11161116
else
11171117
FunctionType(args.length, isContextual).appliedTo(args ::: resultType :: Nil)
11181118
def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
1119-
ft.dealias match
1119+
ft match
11201120
case PolyFunctionOf(mt: MethodType) =>
11211121
Some(mt.paramInfos, mt.resType, mt.isContextualMethod)
1122-
case dft =>
1123-
val tsym = dft.typeSymbol
1124-
if isFunctionSymbol(tsym) && ft.isRef(tsym) then
1125-
val targs = dft.argInfos
1126-
if (targs.isEmpty) None
1127-
else Some(targs.init, targs.last, tsym.name.isContextFunction)
1128-
else None
1122+
case AppliedType(parent, targs) if isFunctionNType(ft) =>
1123+
Some(targs.init, targs.last, ft.typeSymbol.name.isContextFunction)
1124+
case _ =>
1125+
None
11291126
}
11301127
}
11311128

compiler/src/dotty/tools/dotc/transform/Recheck.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ object Recheck:
115115
* - in function and method parameter types
116116
* - under annotations
117117
*/
118-
def normalizeByName(tp: Type)(using Context): Type = tp match
118+
def normalizeByName(tp: Type)(using Context): Type = tp.dealias match
119119
case tp: ExprType =>
120120
mapExprType(tp)
121121
case tp: PolyType =>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,10 +1990,7 @@ trait Applications extends Compatibility {
19901990
// the arity of that function, otherise -1.
19911991
def paramCount(ref: TermRef) =
19921992
val formals = ref.widen.firstParamTypes
1993-
if formals.length > idx then
1994-
formals(idx) match
1995-
case defn.FunctionOf(args, _, _) => args.length
1996-
case _ => -1
1993+
if formals.length > idx then defn.functionArity(formals(idx))
19971994
else -1
19981995

19991996
val numArgs = args.length

0 commit comments

Comments
 (0)