Skip to content

Commit 7680fc7

Browse files
committed
Fix two crashers
One involved selections on WildcardTypes, the other taking the base type of refinement classes. Both manifested themselves in neg/typeclass-encoding2.scala
1 parent c13f6f4 commit 7680fc7

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ object SymDenotations {
14661466
val builder = new BaseDataBuilder
14671467
for (p <- classParents) {
14681468
if (p.typeSymbol.isClass) builder.addAll(p.typeSymbol.asClass.baseClasses)
1469-
else assert(ctx.mode.is(Mode.Interactive), s"$this has non-class parent: $p")
1469+
else assert(isRefinementClass || ctx.mode.is(Mode.Interactive), s"$this has non-class parent: $p")
14701470
}
14711471
(classSymbol :: builder.baseClasses, builder.baseClassSet)
14721472
}

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,7 @@ object Types {
19671967
def derivedSelect(prefix: Type)(implicit ctx: Context): Type =
19681968
if (prefix eq this.prefix) this
19691969
else if (prefix.isBottomType) prefix
1970+
else if (prefix.isInstanceOf[WildcardType]) WildcardType
19701971
else if (isType) {
19711972
val res =
19721973
if (currentSymbol.is(ClassTypeParam)) argForParam(prefix)

tests/neg/typeclass-encoding2.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Used to crash with:
2+
// assertion failed: class <refinement> has non-class parent
3+
// Once that was fixed, another crash with:
4+
// assertion failed: invalid prefix WildcardType(NoType)
5+
object runtime1 {
6+
7+
trait TypeClass1[A] {
8+
val common: TypeClassCommon1
9+
type This[X] = common.This[X]
10+
}
11+
12+
trait TypeClassCommon1 { self =>
13+
type This[X]
14+
type Instance[X] <: TypeClass1[X]
15+
def inject[A](x: This[A]): Instance[A]// { val common: self.type }
16+
}
17+
18+
trait Extension1[From[_], To[X] <: TypeClass1[X]] extends TypeClassCommon1 {
19+
type This[X] = From[X]
20+
type Instance[X] = To[X]
21+
}
22+
23+
implicit def inject[A, From[_]](x: From[A])
24+
(implicit ev: Extension1[From, _]): ev.Instance[A] { type This[X] = From[X] } =
25+
ev.inject(x) // error: found: ev.To[A], required: ev.To[A]{This = From}
26+
}

0 commit comments

Comments
 (0)