Skip to content

Commit 006e2e4

Browse files
authored
Add missing criterion to subtype check (#16889)
Fixes #16850
2 parents 1a2615b + 2678e67 commit 006e2e4

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
309309
thirdTryNamed(tp2)
310310
else
311311
( (tp1.name eq tp2.name)
312+
&& !sym1.is(Private)
312313
&& tp2.isPrefixDependentMemberRef
313314
&& isSubPrefix(tp1.prefix, tp2.prefix)
314315
&& tp1.signature == tp2.signature

tests/neg/i16850.check

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i16850.scala:7:33 -------------------------------------------------------------
2+
7 | def add(elm: Y): Unit = list = elm :: list // error
3+
| ^^^
4+
| Found: (elm : Y)
5+
| Required: Class.this.Y²
6+
|
7+
| where: Y is a type in class Class
8+
| Y² is a type in trait Trait
9+
|
10+
| longer explanation available when compiling with `-explain`

tests/neg/i16850.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
trait Trait :
3+
type Y
4+
var list: List[Y] = Nil
5+
6+
class Class[Y] extends Trait :
7+
def add(elm: Y): Unit = list = elm :: list // error
8+
9+
object Object extends Class[Int] :
10+
add(42)

0 commit comments

Comments
 (0)