Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused parameters from methods #1867

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ object Validated extends ValidatedInstances with ValidatedFunctions{
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
private[data] final class CatchOnlyPartiallyApplied[T](val dummy: Boolean = true ) extends AnyVal{
def apply[A](f: => A)(implicit T: ClassTag[T], NT: NotNull[T]): Validated[T, A] =
def apply[A](f: => A)(implicit T: ClassTag[T]): Validated[T, A] =
try {
valid(f)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object EitherSyntax {
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
private[syntax] final class CatchOnlyPartiallyApplied[T](val dummy: Boolean = true ) extends AnyVal {
def apply[A](f: => A)(implicit CT: ClassTag[T], NT: NotNull[T]): Either[T, A] =
def apply[A](f: => A)(implicit CT: ClassTag[T]): Either[T, A] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the NT parameter isn't referenced at runtime, it serves an important compile-time role. Consider that you wanted to do something like the following:

scala> Either.catchOnly[NumberFormatException]("foo".toInt)
res2: Either[NumberFormatException,Int] = Left(java.lang.NumberFormatException: For input string: "foo")

If you forget to add the type parameter before this PR you get a compile-time error:

scala> Either.catchOnly("foo".toInt)
<console>:18: error: ambiguous implicit values:
 both method If you are seeing this, you probably need to add an explicit type parameter somewhere, because Null is being inferred. in object NotNull of type => cats.NotNull[Null]
 and method catsAmbiguousNotNullNull2 in object NotNull of type => cats.NotNull[Null]
 match expected type cats.NotNull[Null]
       Either.catchOnly("foo".toInt)

However, with this PR you get a runtime error because Null is inferred as the type parameter:

scala> Either.catchOnly("foo".toInt)
java.lang.NumberFormatException: For input string: "foo"
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  at java.lang.Integer.parseInt(Integer.java:580)
  at java.lang.Integer.parseInt(Integer.java:615)
  at scala.collection.immutable.StringLike.toInt(StringLike.scala:301)
  at scala.collection.immutable.StringLike.toInt$(StringLike.scala:301)
  at scala.collection.immutable.StringOps.toInt(StringOps.scala:29)
  at .$anonfun$res0$1(<console>:15)
  at scala.runtime.java8.JFunction0$mcI$sp.apply(JFunction0$mcI$sp.java:12)
  at cats.syntax.EitherSyntax$CatchOnlyPartiallyApplied$.apply$extension(either.scala:29)
  ... 39 elided

I think that the correct change to make here is to document why this NotNull parameter exists. The same goes for the Validated case.

try {
Right(f)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/partialOrder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait PartialOrderSyntax extends EqSyntax {
new PartialOrderOps[A](a)
}

final class PartialOrderOps[A](lhs: A)(implicit A: PartialOrder[A]) {
final class PartialOrderOps[A](lhs: A) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can someone who knows machinist better than I do weigh in on whether this change is fine (I suspect so, but I want to make sure). cc @non @johnynek

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea about the macro expansion in machinist.

I am not sure that is what is going on here anyway. I think it may be to prevent this class from being allocated without a PartialOrder.

We could I'm not sure if this is even tested sadly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems no longer relevant, since macros have been now removed in preparation for Dotty.

def >(rhs: A): Boolean = macro Ops.binop[A, Boolean]
def >=(rhs: A): Boolean = macro Ops.binop[A, Boolean]
def <(rhs: A): Boolean = macro Ops.binop[A, Boolean]
Expand Down