File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -1132,7 +1132,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
1132
1132
/* >|>*/ trace(i " hasMatchingMember( $tp1 . $name :? ${tp2.refinedInfo}), mbr: ${tp1.member(name).info}" , subtyping) /* <|<*/ {
1133
1133
val rinfo2 = tp2.refinedInfo
1134
1134
1135
- // If the member is an abstract type, compare the member itself
1135
+ // If the member is an abstract type and the prefix is a path , compare the member itself
1136
1136
// instead of its bounds. This case is needed situations like:
1137
1137
//
1138
1138
// class C { type T }
@@ -1148,7 +1148,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
1148
1148
def matchAbstractTypeMember (info1 : Type ) = info1 match {
1149
1149
case TypeBounds (lo, hi) if lo ne hi =>
1150
1150
tp2.refinedInfo match {
1151
- case rinfo2 : TypeBounds =>
1151
+ case rinfo2 : TypeBounds if tp1.widenExpr.isSingleton =>
1152
1152
val ref1 = tp1.widenExpr.select(name)
1153
1153
isSubType(rinfo2.lo, ref1) && isSubType(ref1, rinfo2.hi)
1154
1154
case _ =>
Original file line number Diff line number Diff line change
1
+ abstract class Foo {
2
+ type A
3
+ var elem : A
4
+ }
5
+
6
+ object Test {
7
+ def setFirstInList [T ](list : List [Foo { type A = T }]) = {
8
+ list(0 ).elem = list(1 ).elem
9
+ }
10
+
11
+ def main (args : Array [String ]): Unit = {
12
+ val fooInt = new Foo { type A = Int ; var elem = 1 }
13
+ val fooString = new Foo { type A = String ; var elem = " " }
14
+
15
+ val list : List [Foo ] = List (fooInt, fooString)
16
+ setFirstInList[Foo # A ](list) // error
17
+ setFirstInList(list) // error
18
+ println(fooInt.elem + 1 )
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ trait Bar {
2
+ type A
3
+ }
4
+
5
+ object Test {
6
+ def test0 : Unit = {
7
+ val b1 : Bar = new Bar {}
8
+ val b2 : Bar { type A = Bar # A } = b1 // error
9
+ }
10
+ def test1 : Unit = {
11
+ val b1 : List [Bar ] = List (new Bar {})
12
+ val b2 : List [Bar { type A = Bar # A }] = b1 // error
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments