Skip to content

Commit 5482680

Browse files
committed
Add is type to Predef
1 parent 5df5f3e commit 5482680

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

library/src/scala/runtime/stdLibPatches/Predef.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,16 @@ object Predef:
6161
inline def ne(inline y: AnyRef | Null): Boolean =
6262
!(x eq y)
6363

64+
/** A type supporting Self-based type classes.
65+
*
66+
* A is TC
67+
*
68+
* expands to
69+
*
70+
* TC { type Self = A }
71+
*
72+
* which is what is needed for a context bound `[A: TC]`.
73+
*/
74+
infix type is[A <: AnyKind, B <: {type Self <: AnyKind}] = B { type Self = A }
75+
6476
end Predef

tests/pos/parsercombinators-arrow.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//> using options -language:experimental.modularity -source future
22
import collection.mutable
33

4-
infix type is[A <: AnyKind, B <: {type Self <: AnyKind}] = B { type Self = A }
5-
64
/// A parser combinator.
75
trait Combinator:
86

tests/pos/typeclasses-arrow.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//> using options -language:experimental.modularity -source future
22

3-
// this should go in Predef
4-
infix type is[A <: AnyKind, B <: {type Self <: AnyKind}] = B { type Self = A }
5-
63
class Common:
74

85
trait Ord:

tests/pos/typeclasses-this.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//> using options -language:experimental.modularity -source future
22

3-
// this should go in Predef
4-
infix type is[A <: AnyKind, B <: {type Self <: AnyKind}] = B { type Self = A }
5-
63
class Common:
74

85
trait Ord:

tests/pos/typeclasses.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class Common:
2626
def flatMap[B](f: A => Self[B]): Self[B]
2727
def map[B](f: A => B) = x.flatMap(f `andThen` pure)
2828

29-
infix type is[A <: AnyKind, B <: {type Self <: AnyKind}] = B { type Self = A }
30-
3129
end Common
3230

3331

@@ -132,7 +130,6 @@ instance Sheep: Animal with
132130
override def talk(): Unit =
133131
println(s"$name pauses briefly... $noise")
134132
*/
135-
import Instances.is
136133

137134
// Implement the `Animal` trait for `Sheep`.
138135
given (Sheep is Animal) with

0 commit comments

Comments
 (0)