-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #592 from ceedubs/fromTryCatch
Don't infer Null in fromTryCatch
- Loading branch information
Showing
7 changed files
with
79 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cats | ||
|
||
/** | ||
* An instance of `NotNull[A]` indicates that `A` does not have a static type | ||
* of `Null`. | ||
* | ||
* This can be useful in preventing `Null` from being inferred when a type | ||
* parameter is omitted. | ||
*/ | ||
sealed trait NotNull[A] | ||
|
||
object NotNull { | ||
/** | ||
* Since NotNull is just a marker trait with no functionality, it's safe to | ||
* reuse a single instance of it. This helps prevent unnecessary allocations. | ||
*/ | ||
private[this] val singleton: NotNull[Any] = new NotNull[Any] {} | ||
|
||
private[this] def ambiguousException: Exception = new Exception("An instance of NotNull[Null] was used. This should never happen. Both ambiguous NotNull[Null] instances should always be in scope if one of them is.") | ||
|
||
implicit def `If you are seeing this, you probably need to add an explicit type parameter somewhere, beause Null is being inferred.`: NotNull[Null] = throw ambiguousException | ||
|
||
implicit def ambiguousNull2: NotNull[Null] = throw ambiguousException | ||
|
||
implicit def notNull[A]: NotNull[A] = singleton.asInstanceOf[NotNull[A]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters