Skip to content

Commit cb09305

Browse files
committed
Another tweak to hasUnknownMembers
Needed to make latest instance of typeclass-encoding2 pass. Compared to previous this one has a single type parameter for `Extension`.
1 parent 3266593 commit cb09305

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ object ProtoTypes {
115115
bound.isProvisional && hasUnknownMembers(bound)
116116
}
117117
}
118+
case tp: AppliedType => hasUnknownMembers(tp.tycon) || hasUnknownMembers(tp.superType)
118119
case tp: TypeProxy => hasUnknownMembers(tp.superType)
119120
case _ => false
120121
}

tests/pos/typeclass-encoding2.scala

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ object runtime {
4040
}
4141

4242
trait TypeClassCompanion {
43-
type Impl[T] <: Extension[T, _]
43+
type Impl[T] <: Extension[T]
4444
def impl[T](implicit ev: Impl[T]): Impl[T] = ev
4545
}
4646

47-
trait Extension[From, To <: TypeClass] extends TypeClassCommon {
47+
trait Extension[From] extends TypeClassCommon {
4848
type This = From
49-
type Instance = To
5049
}
5150

5251
implicit def inject[From](x: From)
53-
(implicit ev: Extension[From, _]): ev.Instance { type This = From } =
52+
(implicit ev: Extension[From]): ev.Instance { type This = From } =
5453
ev.inject(x)
5554
}
5655
import runtime._
@@ -66,7 +65,7 @@ object semiGroups {
6665
type Instance <: SemiGroup
6766
}
6867
object SemiGroup extends TypeClassCompanion {
69-
type Impl[T] = Extension[T, SemiGroup] with SemiGroupCommon
68+
type Impl[T] = Extension[T] with SemiGroupCommon
7069
}
7170

7271
trait Monoid extends SemiGroup {
@@ -78,10 +77,10 @@ object semiGroups {
7877
def unit: This
7978
}
8079
object Monoid extends TypeClassCompanion {
81-
type Impl[T] = Extension[T, Monoid] with MonoidCommon
80+
type Impl[T] = Extension[T] with MonoidCommon
8281
}
8382

84-
implicit object IntOps extends Extension[Int, Monoid] with MonoidCommon {
83+
implicit object IntOps extends Extension[Int] with MonoidCommon {
8584
type This = Int
8685
type Instance = Monoid
8786
def unit: Int = 0
@@ -91,7 +90,7 @@ object semiGroups {
9190
}
9291
}
9392

94-
implicit object StringOps extends Extension[String, Monoid] with MonoidCommon {
93+
implicit object StringOps extends Extension[String] with MonoidCommon {
9594
type This = String
9695
type Instance = Monoid
9796
def unit = ""
@@ -101,7 +100,7 @@ object semiGroups {
101100
}
102101
}
103102

104-
def sum[T](xs: List[T])(implicit $ev: Monoid.Impl[T]) =
103+
def sum[T](xs: List[T])(implicit ev: Monoid.Impl[T]) =
105104
(Monoid.impl[T].unit /: xs)((x, y) => x `add` y)
106105
}
107106

@@ -156,10 +155,10 @@ object ord {
156155
def minimum: This
157156
}
158157
object Ord extends TypeClassCompanion {
159-
type Impl[T] = Extension[T, Ord] with OrdCommon
158+
type Impl[T] = Extension[T] with OrdCommon
160159
}
161160

162-
implicit object IntOrd extends Extension[Int, Ord] with OrdCommon {
161+
implicit object IntOrd extends Extension[Int] with OrdCommon {
163162
type This = Int
164163
type Instance = Ord
165164
val minimum: Int = Int.MinValue
@@ -171,7 +170,7 @@ object ord {
171170
}
172171

173172
class ListOrd[T](implicit ev: Ord.Impl[T])
174-
extends Extension[List[T], Ord] with OrdCommon { self =>
173+
extends Extension[List[T]] with OrdCommon { self =>
175174
type This = List[T]
176175
type Instance = Ord
177176
def minimum: List[T] = Nil
@@ -246,17 +245,16 @@ object runtime1 {
246245
}
247246

248247
trait TypeClassCompanion1 {
249-
type Impl[T[_]] <: Extension1[T, _]
248+
type Impl[T[_]] <: Extension1[T]
250249
def impl[T[_]](implicit ev: Impl[T]): Impl[T] = ev
251250
}
252251

253-
trait Extension1[From[_], To[X] <: TypeClass1] extends TypeClassCommon1 {
252+
trait Extension1[From[_]] extends TypeClassCommon1 {
254253
type This[X] = From[X]
255-
type Instance[X] = To[X]
256254
}
257255

258256
implicit def inject1[A, From[_]](x: From[A])
259-
(implicit ev: Extension1[From, _]): ev.Instance[A] { type This = From } =
257+
(implicit ev: Extension1[From]): ev.Instance[A] { type This = From } =
260258
ev.inject(x)
261259
}
262260
import runtime1._
@@ -273,7 +271,7 @@ object functors {
273271
def pure[A](x: A): This[A]
274272
}
275273
object Functor extends TypeClassCompanion1 {
276-
type Impl[T[_]] = Extension1[T, Functor] with FunctorCommon
274+
type Impl[T[_]] = Extension1[T] with FunctorCommon
277275
}
278276

279277
trait Monad[A] extends Functor[A] {
@@ -286,14 +284,14 @@ object functors {
286284
type Instance[X] <: Monad[X]
287285
}
288286
object Monad extends TypeClassCompanion1 {
289-
type Impl[T[_]] = Extension1[T, Monad] with MonadCommon
287+
type Impl[T[_]] = Extension1[T] with MonadCommon
290288
}
291289

292290
def develop[A, F[X]](n: Int, x: A, f: A => A)(implicit ev: Functor.Impl[F]): F[A] =
293291
if (n == 0) Functor.impl[F].pure(x)
294292
else develop(n - 1, x, f).map(f)
295293

296-
implicit object ListMonad extends Extension1[List, Monad] with MonadCommon {
294+
implicit object ListMonad extends Extension1[List] with MonadCommon {
297295
type This[A] = List[A]
298296
type Instance = Monad
299297
def pure[A](x: A) = x :: Nil

0 commit comments

Comments
 (0)