Skip to content

Commit

Permalink
Make the vals inside all 'Ops' style classes private (#2617)
Browse files Browse the repository at this point in the history
* Make the vals inside all 'Ops' style classes private

* added an test for partially applied value class dummy type

* Fix compilation and add one more test
  • Loading branch information
coltfred authored and Luka Jacobowitz committed Nov 18, 2018
1 parent 533cc16 commit e1a7cfc
Show file tree
Hide file tree
Showing 37 changed files with 169 additions and 85 deletions.
4 changes: 3 additions & 1 deletion binCompatTest/src/main/scala/catsBC/MimaExceptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ object MimaExceptions {
cats.data.OptionT.catsDataMonadErrorMonadForOptionT[List],
FunctionK.lift(headOption),
"blah".leftNec[Int],
List(Some(4), None).nested
List(Some(4), None).nested,
cats.data.EitherT.left[Int](Option("err")),
true.iterateUntilM(Option(_))(identity _)
)

}
91 changes: 86 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,92 @@ def mimaSettings(moduleName: String) =
exclude[DirectMissingMethodProblem]("cats.data.KleisliInstances1.catsDataCommutativeArrowForKleisli"),
exclude[DirectMissingMethodProblem]("cats.data.KleisliInstances4.catsDataCommutativeFlatMapForKleisli"),
exclude[DirectMissingMethodProblem]("cats.data.IRWSTInstances1.catsDataStrongForIRWST"),
exclude[DirectMissingMethodProblem]("cats.data.OptionTInstances1.catsDataMonadErrorMonadForOptionT"),
//These 2 things are `.value` on a Ops class (which shouldn't have ever been exposed) - See #2514 and #2613.
exclude[DirectMissingMethodProblem]("cats.syntax.EitherIdOpsBinCompat0.value"),
exclude[DirectMissingMethodProblem]("cats.syntax.NestedIdOps.value")
) ++ // Only compile-time abstractions (macros) allowed here
exclude[DirectMissingMethodProblem]("cats.data.OptionTInstances1.catsDataMonadErrorMonadForOptionT")
) ++
//These things are Ops classes that shouldn't have the `value` exposed. These should have never been public because they don't
//provide any value. Making them private because of issues like #2514 and #2613.
Seq(
exclude[DirectMissingMethodProblem]("cats.ApplicativeError#LiftFromOptionPartially.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.Const#OfPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.EitherT#CondPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.EitherT#FromEitherPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.EitherT#FromOptionPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.EitherT#LeftPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.EitherT#LeftTPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.EitherT#PurePartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.EitherT#RightPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#BothTPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#CondPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#FromEitherPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#FromIorPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#FromOptionPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#LeftPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#LeftTPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#PurePartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.IorT#RightPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.NonEmptyChainOps.value"),
exclude[DirectMissingMethodProblem]("cats.data.OptionT#FromOptionPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.OptionT#PurePartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.data.Validated#CatchOnlyPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.free.Free#FreeInjectKPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.free.Free#FreeLiftInjectKPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.free.FreeT#FreeTLiftInjectKPartiallyApplied.dummy"),
exclude[DirectMissingMethodProblem]("cats.syntax.ApplicativeErrorIdOps.e"),
exclude[DirectMissingMethodProblem]("cats.syntax.ApplicativeErrorOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.ApplicativeIdOps.a"),
exclude[DirectMissingMethodProblem]("cats.syntax.ApplicativeOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.ApplyOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.BinestedIdOps.value"),
exclude[DirectMissingMethodProblem]("cats.syntax.BitraverseOps.fab"),
exclude[DirectMissingMethodProblem]("cats.syntax.DistributiveOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.EitherIdOps.obj"),
exclude[DirectMissingMethodProblem]("cats.syntax.EitherIdOpsBinCompat0.value"),
exclude[DirectMissingMethodProblem]("cats.syntax.EitherKOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.EitherObjectOps.either"),
exclude[DirectMissingMethodProblem]("cats.syntax.EitherOps.eab"),
exclude[DirectMissingMethodProblem]("cats.syntax.EitherOpsBinCompat0.value"),
exclude[DirectMissingMethodProblem]("cats.syntax.FlatMapIdOps.a"),
exclude[DirectMissingMethodProblem]("cats.syntax.FlatMapOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.FlatMapOptionOps.fopta"),
exclude[DirectMissingMethodProblem]("cats.syntax.FlattenOps.ffa"),
exclude[DirectMissingMethodProblem]("cats.syntax.FoldableOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.GuardOps.condition"),
exclude[DirectMissingMethodProblem]("cats.syntax.IfMOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.IndexOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.IorIdOps.a"),
exclude[DirectMissingMethodProblem]("cats.syntax.LeftOps.left"),
exclude[DirectMissingMethodProblem]("cats.syntax.ListOps.la"),
exclude[DirectMissingMethodProblem]("cats.syntax.ListOpsBinCompat0.la"),
exclude[DirectMissingMethodProblem]("cats.syntax.MonadErrorOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.MonadErrorRethrowOps.fea"),
exclude[DirectMissingMethodProblem]("cats.syntax.MonadIdOps.a"),
exclude[DirectMissingMethodProblem]("cats.syntax.MonadOps.fa"),
exclude[DirectMissingMethodProblem]("cats.syntax.MonoidOps.lhs"),
exclude[DirectMissingMethodProblem]("cats.syntax.NestedBitraverseOps.fgagb"),
exclude[DirectMissingMethodProblem]("cats.syntax.NestedFoldableOps.fga"),
exclude[DirectMissingMethodProblem]("cats.syntax.NestedIdOps.value"),
exclude[DirectMissingMethodProblem]("cats.syntax.NestedReducibleOps.fga"),
exclude[DirectMissingMethodProblem]("cats.syntax.OptionIdOps.a"),
exclude[DirectMissingMethodProblem]("cats.syntax.OptionOps.oa"),
exclude[DirectMissingMethodProblem]("cats.syntax.ParallelApOps.ma"),
exclude[DirectMissingMethodProblem]("cats.syntax.ParallelFlatSequenceOps.tmta"),
exclude[DirectMissingMethodProblem]("cats.syntax.ParallelFlatTraversableOps.ta"),
exclude[DirectMissingMethodProblem]("cats.syntax.ParallelSequence_Ops.tma"),
exclude[DirectMissingMethodProblem]("cats.syntax.ParallelSequenceOps.tma"),
exclude[DirectMissingMethodProblem]("cats.syntax.ParallelTraversable_Ops.ta"),
exclude[DirectMissingMethodProblem]("cats.syntax.ParallelTraversableOps.ta"),
exclude[DirectMissingMethodProblem]("cats.syntax.RightOps.right"),
exclude[DirectMissingMethodProblem]("cats.syntax.SeparateOps.fgab"),
exclude[DirectMissingMethodProblem]("cats.syntax.SetOps.se"),
exclude[DirectMissingMethodProblem]("cats.syntax.TabulateOps.f"),
exclude[DirectMissingMethodProblem]("cats.syntax.TryOps.self"),
exclude[DirectMissingMethodProblem]("cats.syntax.UniteOps.fga"),
exclude[DirectMissingMethodProblem]("cats.syntax.ValidatedExtension.self"),
exclude[DirectMissingMethodProblem]("cats.syntax.ValidatedIdOpsBinCompat0.a"),
exclude[DirectMissingMethodProblem]("cats.syntax.ValidatedIdSyntax.a"),
exclude[DirectMissingMethodProblem]("cats.syntax.VectorOps.va"),
exclude[DirectMissingMethodProblem]("cats.syntax.WriterIdSyntax.a")
) ++ // Only compile-time abstractions (macros) allowed here
Seq(
exclude[IncompatibleMethTypeProblem]("cats.arrow.FunctionKMacros.lift"),
exclude[MissingTypesProblem]("cats.arrow.FunctionKMacros$"),
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/ApplicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ trait ApplicativeError[F[_], E] extends Applicative[F] {
object ApplicativeError {
def apply[F[_], E](implicit F: ApplicativeError[F, E]): ApplicativeError[F, E] = F

final private[cats] class LiftFromOptionPartially[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[cats] class LiftFromOptionPartially[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[E, A](oa: Option[A], ifEmpty: => E)(implicit F: ApplicativeError[F, _ >: E]): F[A] =
oa match {
case Some(a) => F.pure(a)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Const.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object Const extends ConstInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class OfPartiallyApplied[B](val dummy: Boolean = true) extends AnyVal {
final private[data] class OfPartiallyApplied[B](private val dummy: Boolean = true) extends AnyVal {
def apply[A](a: A): Const[A, B] = Const(a)
}

Expand Down
14 changes: 7 additions & 7 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ object EitherT extends EitherTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class LeftPartiallyApplied[B](val dummy: Boolean = true) extends AnyVal {
final private[data] class LeftPartiallyApplied[B](private val dummy: Boolean = true) extends AnyVal {
def apply[F[_], A](fa: F[A])(implicit F: Functor[F]): EitherT[F, A, B] = EitherT(F.map(fa)(Either.left))
}

Expand All @@ -324,7 +324,7 @@ object EitherT extends EitherTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class LeftTPartiallyApplied[F[_], B](val dummy: Boolean = true) extends AnyVal {
final private[data] class LeftTPartiallyApplied[F[_], B](private val dummy: Boolean = true) extends AnyVal {
def apply[A](a: A)(implicit F: Applicative[F]): EitherT[F, A, B] = EitherT(F.pure(Either.left(a)))
}

Expand All @@ -342,7 +342,7 @@ object EitherT extends EitherTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class RightPartiallyApplied[A](val dummy: Boolean = true) extends AnyVal {
final private[data] class RightPartiallyApplied[A](private val dummy: Boolean = true) extends AnyVal {
def apply[F[_], B](fb: F[B])(implicit F: Functor[F]): EitherT[F, A, B] = EitherT(F.map(fb)(Either.right))
}

Expand All @@ -360,7 +360,7 @@ object EitherT extends EitherTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class PurePartiallyApplied[F[_], A](val dummy: Boolean = true) extends AnyVal {
final private[data] class PurePartiallyApplied[F[_], A](private val dummy: Boolean = true) extends AnyVal {
def apply[B](b: B)(implicit F: Applicative[F]): EitherT[F, A, B] = right(F.pure(b))
}

Expand Down Expand Up @@ -435,7 +435,7 @@ object EitherT extends EitherTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class FromEitherPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class FromEitherPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[E, A](either: Either[E, A])(implicit F: Applicative[F]): EitherT[F, E, A] =
EitherT(F.pure(either))
}
Expand All @@ -456,7 +456,7 @@ object EitherT extends EitherTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class FromOptionPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class FromOptionPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[E, A](opt: Option[A], ifNone: => E)(implicit F: Applicative[F]): EitherT[F, E, A] =
EitherT(F.pure(Either.fromOption(opt, ifNone)))
}
Expand Down Expand Up @@ -494,7 +494,7 @@ object EitherT extends EitherTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class CondPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class CondPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[E, A](test: Boolean, right: => A, left: => E)(implicit F: Applicative[F]): EitherT[F, E, A] =
EitherT(F.pure(Either.cond(test, right, left)))
}
Expand Down
18 changes: 9 additions & 9 deletions core/src/main/scala/cats/data/IorT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class LeftPartiallyApplied[B](val dummy: Boolean = true) extends AnyVal {
final private[data] class LeftPartiallyApplied[B](private val dummy: Boolean = true) extends AnyVal {
def apply[F[_], A](fa: F[A])(implicit F: Functor[F]): IorT[F, A, B] = IorT(F.map(fa)(Ior.left))
}

Expand All @@ -148,7 +148,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class LeftTPartiallyApplied[F[_], B](val dummy: Boolean = true) extends AnyVal {
final private[data] class LeftTPartiallyApplied[F[_], B](private val dummy: Boolean = true) extends AnyVal {
def apply[A](a: A)(implicit F: Applicative[F]): IorT[F, A, B] = IorT(F.pure(Ior.left(a)))
}

Expand All @@ -167,7 +167,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class RightPartiallyApplied[A](val dummy: Boolean = true) extends AnyVal {
final private[data] class RightPartiallyApplied[A](private val dummy: Boolean = true) extends AnyVal {
def apply[F[_], B](fb: F[B])(implicit F: Functor[F]): IorT[F, A, B] = IorT(F.map(fb)(Ior.right))
}

Expand Down Expand Up @@ -208,7 +208,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class BothTPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class BothTPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[A, B](a: A, b: B)(implicit F: Applicative[F]): IorT[F, A, B] = IorT(F.pure(Ior.Both(a, b)))
}

Expand All @@ -226,7 +226,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class PurePartiallyApplied[F[_], A](val dummy: Boolean = true) extends AnyVal {
final private[data] class PurePartiallyApplied[F[_], A](private val dummy: Boolean = true) extends AnyVal {
def apply[B](b: B)(implicit F: Applicative[F]): IorT[F, A, B] = IorT(F.pure(Ior.right(b)))
}

Expand Down Expand Up @@ -274,7 +274,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class FromIorPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class FromIorPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[A, B](ior: Ior[A, B])(implicit F: Applicative[F]): IorT[F, A, B] = IorT(F.pure(ior))
}

Expand All @@ -293,7 +293,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class FromEitherPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class FromEitherPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[E, A](either: Either[E, A])(implicit F: Applicative[F]): IorT[F, E, A] = IorT(F.pure(either.toIor))
}

Expand Down Expand Up @@ -325,7 +325,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class FromOptionPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class FromOptionPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[E, A](option: Option[A], ifNone: => E)(implicit F: Applicative[F]): IorT[F, E, A] =
IorT(F.pure(option.toRightIor(ifNone)))
}
Expand Down Expand Up @@ -363,7 +363,7 @@ object IorT extends IorTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class CondPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class CondPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[A, B](test: Boolean, right: => B, left: => A)(implicit F: Applicative[F]): IorT[F, A, B] =
IorT(F.pure(if (test) Ior.right(right) else Ior.left(left)))
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/NonEmptyChain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private[data] object NonEmptyChainImpl extends NonEmptyChainInstances {
new NonEmptyChainOps(value)
}

class NonEmptyChainOps[A](val value: NonEmptyChain[A]) extends AnyVal {
class NonEmptyChainOps[A](private val value: NonEmptyChain[A]) extends AnyVal {

/**
* Converts this chain to a `Chain`
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/OptionT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ object OptionT extends OptionTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class PurePartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class PurePartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[A](value: A)(implicit F: Applicative[F]): OptionT[F, A] =
OptionT(F.pure(Some(value)))
}
Expand Down Expand Up @@ -201,7 +201,7 @@ object OptionT extends OptionTInstances {
/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
final private[data] class FromOptionPartiallyApplied[F[_]](val dummy: Boolean = true) extends AnyVal {
final private[data] class FromOptionPartiallyApplied[F[_]](private val dummy: Boolean = true) extends AnyVal {
def apply[A](value: Option[A])(implicit F: Applicative[F]): OptionT[F, A] =
OptionT(F.pure(value))
}
Expand Down
Loading

0 comments on commit e1a7cfc

Please sign in to comment.