Add explanation to checkCaseClassInheritanceInvariant error msg#20141
Add explanation to checkCaseClassInheritanceInvariant error msg#20141EugeneFlesselle merged 2 commits intoscala:mainfrom
Conversation
Closes scala#18552 which was actually not an error, see: https://github.com/scala/scala3/blob/73882c5b62b8cd96031ad975f7677949433a9f21/compiler/src/dotty/tools/dotc/typer/RefChecks.scala#L889-L893 Co-authored-by: Anna Herlihy <herlihyap@gmail.com> Co-authored-by: Natsu Kagami <natsukagami@gmail.com>
9a04756 to
fd84324
Compare
mbovel
left a comment
There was a problem hiding this comment.
Looks okay to me!
Two minor questions:
- Is the word "conflicting" really appropriate here? If it is easy to change, maybe I'd write something like "class MB cannot inherit from two instances of base trait M".
- Is it clear that "enabling better GADT constraints" explains why it is implemented that way? Maybe split in a second sentence "This is an implementation limitation that enables better GADT constraints in case class patterns".
|
@SimonGuilloud what do you think? Would this message have helped? |
Technically speaking, it can inherit from two instances trait M[+T]
case class MAny(id:Int) extends M[Int]
class MInt(id:Int) extends MAny(id) with M[Any]
// Ok: they do not conflict since M[Int] <: M[Any]
trait M[+T]
case class Mcc(id:Int)
class MAny(id:Int) extends Mcc(id) with M[Any]
class MInt(id:Int) extends MAny(id) with M[Int]
// Ok: the "conflicting" instances are only below the case class
trait M[+T]
case class MAny(id:Int) extends M[Any]
class MInt(id:Int) extends MAny(id) with M[Int]
// Error because M[Int] refines M[Any] which is a base type of an intermediate case class
I agree that's better 👍 |
|
I think it is certainly better ("This error is blatantly wrong" => "I don't understand the message but alright"). |
Closes #18552 which was actually not an error, see: https://github.com/scala/scala3/blob/73882c5b62b8cd96031ad975f7677949433a9f21/compiler/src/dotty/tools/dotc/typer/RefChecks.scala#L889-L893 --------- Co-authored-by: Anna Herlihy <herlihyap@gmail.com> Co-authored-by: Natsu Kagami <natsukagami@gmail.com> [Cherry-picked ed9fecc][modified]
Closes #18552 which was actually not an error, see:
scala3/compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Lines 889 to 893 in 73882c5
Co-authored-by: Anna Herlihy herlihyap@gmail.com
Co-authored-by: Natsu Kagami natsukagami@gmail.com