diff --git a/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Check.scala b/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Check.scala index dc94276..c1d0eff 100644 --- a/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Check.scala +++ b/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Check.scala @@ -257,7 +257,7 @@ final class Check(pipelineContext: PipelineContext) { } else { ty } - val funTys = narrow.asFunType(funTy, args.size).get + val funTys = narrow.extractFunTypes(funTy, args.size) val (argTys, env2) = elab.elabExprs(args, env1) if (funTys.nonEmpty) { funTys.foreach { ft => diff --git a/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Elab.scala b/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Elab.scala index b49ef8e..13ebc34 100644 --- a/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Elab.scala +++ b/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Elab.scala @@ -188,7 +188,7 @@ final class Elab(pipelineContext: PipelineContext) { } else { ty } - val funTys = narrow.asFunType(funTy, args.size).get + val funTys = narrow.extractFunTypes(funTy, args.size) if (funTys.isEmpty) { val (_, env2) = elabExprs(args, env1) (NoneType, env2) diff --git a/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/ElabApplyCustom.scala b/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/ElabApplyCustom.scala index 0ddb4d9..8fe9864 100644 --- a/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/ElabApplyCustom.scala +++ b/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/ElabApplyCustom.scala @@ -150,7 +150,7 @@ class ElabApplyCustom(pipelineContext: PipelineContext) { diagnosticsInfo.add(ExpectedSubtype(funArg.pos, funArg, expected = expFunTy, got = funArgTy)) List(DynamicType) } else - narrow.asFunType(funArgTy, 1).get.map(_.resTy) + narrow.extractFunTypes(funArgTy, 1).map(_.resTy) } def funResultsToItemTy(tys: Iterable[Type], defaultTy: Type, pos: Pos): Type = tys.foldLeft(NoneType: Type)((memo, ty) => subtype.join(memo, funResultToItemTy(ty, defaultTy, pos))) @@ -285,7 +285,7 @@ class ElabApplyCustom(pipelineContext: PipelineContext) { case _ => val expFunTy = FunType(Nil, List(keyTy, valTy, accTy), AnyType) val funArgCoercedTy = coerce(funArg, funArgTy, expFunTy) - val vTys = narrow.asFunType(funArgCoercedTy, 3).get.map(_.resTy) + val vTys = narrow.extractFunTypes(funArgCoercedTy, 3).map(_.resTy).toList accTy1 :: vTys } def validateAccumulatorTy(accTy: Type): Unit = funArg match { @@ -385,7 +385,7 @@ class ElabApplyCustom(pipelineContext: PipelineContext) { subtype.join(vTys) case _ => val funArgCoercedTy = coerce(funArg, funArgTy, expFunTy) - val vTys = narrow.asFunType(funArgCoercedTy, 2).get.map(_.resTy) + val vTys = narrow.extractFunTypes(funArgCoercedTy, 2).map(_.resTy) subtype.join(vTys) } def mapValueType(argMapTy: Type, argValTy: Type): Type = argMapTy match { @@ -418,7 +418,7 @@ class ElabApplyCustom(pipelineContext: PipelineContext) { .map((clause, occEnv) => elab.elabClause(clause, List(keyTy, valTy), occEnv, Set.empty)._1) case _ => val funArgCoercedTy = coerce(funArg, funArgTy, expFunTy) - narrow.asFunType(funArgCoercedTy, 2).get.map(_.resTy) + narrow.extractFunTypes(funArgCoercedTy, 2).map(_.resTy) } def funResultsToValTy(tys: Iterable[Type], defaultTy: Type, pos: Pos): Type = tys.foldLeft(NoneType: Type)((memo, ty) => subtype.join(memo, funResultToValTy(ty, defaultTy, pos))) diff --git a/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Narrow.scala b/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Narrow.scala index 603e03d..485cda8 100644 --- a/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Narrow.scala +++ b/eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Narrow.scala @@ -232,38 +232,6 @@ class Narrow(pipelineContext: PipelineContext) { List() } - def asFunType(ty: Type, arity: Int): Option[List[FunType]] = - asFunTypeAux(ty, arity) - - def asFunTypeAux(ty: Type, arity: Int): Option[List[FunType]] = ty match { - case DynamicType => - Some(List(FunType(List.empty, List.fill(arity)(DynamicType), DynamicType))) - case BoundedDynamicType(bound) => - asFunTypeAux(bound, arity).map(fts => - fts.map(ft => FunType(ft.forall, ft.argTys.map(BoundedDynamicType), BoundedDynamicType(ft.resTy))) - ) - case AnyFunType => - Some(List(FunType(List.empty, List.fill(arity)(DynamicType), DynamicType))) - case AnyArityFunType(resTy) => - Some(List(FunType(List.empty, List.fill(arity)(DynamicType), resTy))) - case _ if subtype.isNoneType(ty) => - Some(List()) - case ft: FunType => - if (ft.argTys.size == arity) Some(List(ft)) - else None - case UnionType(tys) => - val subResults = tys.map(asFunTypeAux(_, arity)) - if (subResults.exists(_.isEmpty)) None - else Some(subResults.toList.flatMap(_.get)) - case RemoteType(rid, args) => - val body = util.getTypeDeclBody(rid, args) - asFunTypeAux(body, arity) - case OpaqueType(rid, _) => - None - case _ => - None - } - def extractFunTypes(ty: Type, arity: Int): Set[FunType] = ty match { case DynamicType => Set(FunType(List.empty, List.fill(arity)(DynamicType), DynamicType))