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

Remove unused parameters from methods #1867

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 27, 2017

see also #1632 (review)
scala/scala#5402 (comment)
scala/scala#5876

See #1669 for related work on MonadError and ApplicativeError

@codecov-io
Copy link

codecov-io commented Aug 27, 2017

Codecov Report

Merging #1867 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1867      +/-   ##
==========================================
- Coverage   94.96%   94.92%   -0.05%     
==========================================
  Files         241      241              
  Lines        4193     4193              
  Branches      109      117       +8     
==========================================
- Hits         3982     3980       -2     
- Misses        211      213       +2
Impacted Files Coverage Δ
core/src/main/scala/cats/syntax/partialOrder.scala 0% <ø> (ø) ⬆️
core/src/main/scala/cats/data/Validated.scala 100% <ø> (ø) ⬆️
core/src/main/scala/cats/syntax/either.scala 99.13% <ø> (ø) ⬆️
core/src/main/scala/cats/NotNull.scala 0% <0%> (-40%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2db490a...d6f7052. Read the comment docs.

@ghost
Copy link
Author

ghost commented Aug 27, 2017

The failing coverage test is :

private[this] val singleton: NotNull[Any] = new NotNull[Any] {}
implicit def catsNotNullForA[A]: NotNull[A] = singleton.asInstanceOf[NotNull[A]]

So, iff it's OK to change them in the API in this PR (and I suspect not, actually), the next question is whether to remove these two lines or add tests for them.

If they should stay, perhaps I should comment accordingly?

Copy link
Contributor

@ceedubs ceedubs left a comment

Choose a reason for hiding this comment

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

Thanks @BennyHill! I left a comment about why I don't think that we can remove the NotNull parameters, but I suspect the other change is a good one, and I'm glad that you pointed out that the NotNull usage is not very well documented.

@@ -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.

@@ -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.

ceedubs added a commit to ceedubs/cats that referenced this pull request Dec 13, 2017
The main goal of this PR was to add syntax for the `Order` and
`PartialOrder` syntax (provided via machinist ops) to address [this comment](typelevel#1867 (comment)).

In the process I noticed that the Order companion object didn't have a
`comparison` function to forward through to the type class instance like
it did for other methods, so I added that.

I did notice that the `Order`/`PartialOrder` syntax does work whether or
not you take the `Order`/`PartialOrder` instances as implicit parameters
to the ops classes. I think that only @non understands quite what's
going on with the machinist syntax macros, so I didn't make the changes
to take away those implicit parameters without knowing the implications.
The tests pass either way, so I think that end-code should work for
users either way.
LukaJCB pushed a commit that referenced this pull request Dec 17, 2017
* Add comparison method in Order companion object

The main goal of this PR was to add syntax for the `Order` and
`PartialOrder` syntax (provided via machinist ops) to address [this comment](#1867 (comment)).

In the process I noticed that the Order companion object didn't have a
`comparison` function to forward through to the type class instance like
it did for other methods, so I added that.

I did notice that the `Order`/`PartialOrder` syntax does work whether or
not you take the `Order`/`PartialOrder` instances as implicit parameters
to the ops classes. I think that only @non understands quite what's
going on with the machinist syntax macros, so I didn't make the changes
to take away those implicit parameters without knowing the implications.
The tests pass either way, so I think that end-code should work for
users either way.

* Change PartialOrder syntax tests to handle NaN
@larsrh larsrh closed this Apr 11, 2020
@larsrh
Copy link
Contributor

larsrh commented Apr 11, 2020

Closing this because the two proposed changes are not desired or now outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants