Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NTPape committed Mar 17, 2022
1 parent 293e6c5 commit 661147d
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private[focus] trait SelectParserBase extends ParserBase {
val companionObject: Term = Ref(classSymbol.companionModule)

private val (typeParams, caseFieldParams :: otherParams) =
classSymbol.primaryConstructor.paramSymss.span(_.head.isTypeParam)
classSymbol.primaryConstructor.paramSymss.span(_.headOption.fold(false)(_.isTypeParam))
val hasOnlyOneCaseField: Boolean = caseFieldParams.length == 1
val hasOnlyOneParameterList: Boolean = otherParams.isEmpty
private val nonCaseNonImplicitParameters: List[Symbol] =
Expand All @@ -32,7 +32,10 @@ private[focus] trait SelectParserBase extends ParserBase {
case None => FocusError.NotACaseField(typeRepr.show, fieldName).asResult
}
def getCaseFieldType(caseFieldSymbol: Symbol): FocusResult[TypeRepr] =
getFieldType(typeRepr, caseFieldSymbol)
caseFieldSymbol match {
case FieldType(possiblyTypeArg) => Right(swapWithSuppliedType(typeRepr, possiblyTypeArg))
case _ => FocusError.CouldntFindFieldType(typeRepr.show, caseFieldSymbol.name).asResult
}
}

object CaseClassExtractor {
Expand All @@ -42,25 +45,19 @@ private[focus] trait SelectParserBase extends ParserBase {
}
}

def getSuppliedTypeArgs(fromType: TypeRepr): List[TypeRepr] =
private def getSuppliedTypeArgs(fromType: TypeRepr): List[TypeRepr] =
fromType match {
case AppliedType(_, argTypeReprs) => argTypeReprs
case _ => Nil
}

def getFieldType(fromType: TypeRepr, caseFieldSymbol: Symbol): FocusResult[TypeRepr] =
caseFieldSymbol match {
case FieldType(possiblyTypeArg) => Right(swapWithSuppliedType(fromType, possiblyTypeArg))
case _ => FocusError.CouldntFindFieldType(fromType.show, caseFieldSymbol.name).asResult
}

private object FieldType {
def unapply(fieldSymbol: Symbol): Option[TypeRepr] = fieldSymbol match {
case sym if sym.isNoSymbol => None
case sym =>
sym.tree match {
case ValDef(_, typeTree, _) => Some(typeTree.tpe)
// Only needed for Tuples because `_1` is a DefDef while `_1 ` is a ValDef.
// Only needed for Tuples because `_1` is a DefDef while `_1 ` is the corresponding ValDef.
case DefDef(_, _, typeTree, _) => Some(typeTree.tpe)
case _ => None
}
Expand Down Expand Up @@ -103,10 +100,8 @@ private[focus] trait SelectParserBase extends ParserBase {
case success: ImplicitSearchSuccess => Right(success.tree)
case _ => FocusError.ImplicitNotFound(typeRepr.show).asResult
}

searchForImplicit(t.tpe)
.orElse(searchForImplicit(t.tpe.dealias))
.orElse(searchForImplicit(t.tpe.widen))
.orElse(searchForImplicit(t.tpe.widen.dealias))
.map(acc :+ _)

case (Right(acc), other) =>
Expand Down

0 comments on commit 661147d

Please sign in to comment.