Skip to content

Commit

Permalink
Add missing criterion to subtype check (#16889)
Browse files Browse the repository at this point in the history
Fixes #16850
  • Loading branch information
Kordyjan authored Feb 15, 2023
2 parents 1a2615b + 2678e67 commit 006e2e4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
thirdTryNamed(tp2)
else
( (tp1.name eq tp2.name)
&& !sym1.is(Private)
&& tp2.isPrefixDependentMemberRef
&& isSubPrefix(tp1.prefix, tp2.prefix)
&& tp1.signature == tp2.signature
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/i16850.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- [E007] Type Mismatch Error: tests/neg/i16850.scala:7:33 -------------------------------------------------------------
7 | def add(elm: Y): Unit = list = elm :: list // error
| ^^^
| Found: (elm : Y)
| Required: Class.this.Y²
|
| where: Y is a type in class Class
| Y² is a type in trait Trait
|
| longer explanation available when compiling with `-explain`
10 changes: 10 additions & 0 deletions tests/neg/i16850.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

trait Trait :
type Y
var list: List[Y] = Nil

class Class[Y] extends Trait :
def add(elm: Y): Unit = list = elm :: list // error

object Object extends Class[Int] :
add(42)

0 comments on commit 006e2e4

Please sign in to comment.