Skip to content

Commit 661147d

Browse files
committed
Small fixes
1 parent 293e6c5 commit 661147d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

core/shared/src/main/scala-3.x/monocle/internal/focus/features/SelectParserBase.scala

+8-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private[focus] trait SelectParserBase extends ParserBase {
1616
val companionObject: Term = Ref(classSymbol.companionModule)
1717

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

3841
object CaseClassExtractor {
@@ -42,25 +45,19 @@ private[focus] trait SelectParserBase extends ParserBase {
4245
}
4346
}
4447

45-
def getSuppliedTypeArgs(fromType: TypeRepr): List[TypeRepr] =
48+
private def getSuppliedTypeArgs(fromType: TypeRepr): List[TypeRepr] =
4649
fromType match {
4750
case AppliedType(_, argTypeReprs) => argTypeReprs
4851
case _ => Nil
4952
}
5053

51-
def getFieldType(fromType: TypeRepr, caseFieldSymbol: Symbol): FocusResult[TypeRepr] =
52-
caseFieldSymbol match {
53-
case FieldType(possiblyTypeArg) => Right(swapWithSuppliedType(fromType, possiblyTypeArg))
54-
case _ => FocusError.CouldntFindFieldType(fromType.show, caseFieldSymbol.name).asResult
55-
}
56-
5754
private object FieldType {
5855
def unapply(fieldSymbol: Symbol): Option[TypeRepr] = fieldSymbol match {
5956
case sym if sym.isNoSymbol => None
6057
case sym =>
6158
sym.tree match {
6259
case ValDef(_, typeTree, _) => Some(typeTree.tpe)
63-
// Only needed for Tuples because `_1` is a DefDef while `_1 ` is a ValDef.
60+
// Only needed for Tuples because `_1` is a DefDef while `_1 ` is the corresponding ValDef.
6461
case DefDef(_, _, typeTree, _) => Some(typeTree.tpe)
6562
case _ => None
6663
}
@@ -103,10 +100,8 @@ private[focus] trait SelectParserBase extends ParserBase {
103100
case success: ImplicitSearchSuccess => Right(success.tree)
104101
case _ => FocusError.ImplicitNotFound(typeRepr.show).asResult
105102
}
103+
106104
searchForImplicit(t.tpe)
107-
.orElse(searchForImplicit(t.tpe.dealias))
108-
.orElse(searchForImplicit(t.tpe.widen))
109-
.orElse(searchForImplicit(t.tpe.widen.dealias))
110105
.map(acc :+ _)
111106

112107
case (Right(acc), other) =>

0 commit comments

Comments
 (0)