Skip to content

Commit

Permalink
Simplify defn.FunctionOf.unapply (#18486)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki authored Nov 14, 2023
2 parents e3af2de + 171773d commit 312e4bb
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 @@ -459,7 +459,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 @@ -1143,16 +1143,13 @@ class Definitions {
else FunctionNOf(args, resultType, isContextual)

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 @@ -104,7 +104,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 @@ -2003,10 +2003,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).dealias match
case defn.FunctionNOf(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 312e4bb

Please sign in to comment.