Skip to content

Commit

Permalink
Simplify defn.FunctionOf.unapply
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Sep 19, 2023
1 parent a37dac6 commit a083a7a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
13 changes: 5 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Recheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a083a7a

Please sign in to comment.