Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Formatting.Show for types X | Null.
Once we saw what got changed we got priority errors like this: ```scala [warn] -- Warning: /Users/odersky/workspace/dotty/compiler/src/dotty/tools/dotc/reporting/messages.scala:2145:15 [warn] 2145 | | ${Magenta("case a @ C()")} => 2 [warn] | ^ [warn] |Change in given search preference for dotty.tools.dotc.printing.Formatting.ShownDef.Show[Product | Null] between alternatives (dotty.tools.dotc.printing.Formatting.ShownDef.Show.given_Show_Product : [warn] | dotty.tools.dotc.printing.Formatting.ShownDef.Show[Product]) and (dotty.tools.dotc.printing.Formatting.ShownDef.Show.oldShowNull : [warn] | [X] [warn] | (implicit evidence$1: dotty.tools.dotc.printing.Formatting.ShownDef.Show[X]) [warn] | : dotty.tools.dotc.printing.Formatting.ShownDef.Show.oldShowNull[X] [warn] |) [warn] |Previous choice : the first alternative [warn] |New choice from Scala 3.6: the second alternative ``` I believe there is some funky thing going on with nulls. Probably unsafe nulls somewhere. Anyway what seems to happen is that before Product's given was selected for an argument of `Product | Null`, which seems to indicate that the two types were seen as equivalent. Anyway, if we compare `Show[Product]` with `Show[X | Null]` it seems that Show[Product] won the type score and lost the owner score, so it was a draw. But then the second criterion kicked in which rules that alternatives without any implicit arguments take priority over alternatives with explicit arguments. The given for Product was unconditional but the given for X | Null has a context bound. So Show[Product] won. But once we switch to more general, we have that Show[Product] loses both type and owner score, so Show[X | Null] won. And that seems to have caused the classcast exceptions. I am not sure why, the logic for Shown was too hard for me to follow. The fix is to move Show[X | Null] to have lowest priority.
- Loading branch information