File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -541,7 +541,11 @@ class Namer { typer: Typer =>
541541 res = cpy.TypeDef (modCls)(
542542 rhs = cpy.Template (modTempl)(
543543 derived = if (fromTempl.derived.nonEmpty) fromTempl.derived else modTempl.derived,
544- body = fromTempl.body ++ modTempl.body))
544+ body = fromTempl.body.filter {
545+ case stat : DefDef => stat.name != nme.toString_
546+ // toString should only be generated if explicit companion is missing
547+ case _ => true
548+ } ++ modTempl.body))
545549 if (fromTempl.derived.nonEmpty) {
546550 if (modTempl.derived.nonEmpty)
547551 report.error(em " a class and its companion cannot both have `derives` clauses " , mdef.srcPos)
Original file line number Diff line number Diff line change 1+ trait Companion :
2+ final override def toString : String = " Companion"
3+
4+ case class Example (value : Int )
5+ object Example extends Companion
6+
7+ case class C ()
8+ object C :
9+ override def toString = " CC"
10+
11+ case class D ()
12+
13+ @ main def Test =
14+ assert(Example .toString == " Companion" )
15+ assert(C .toString == " CC" )
16+ assert(D .toString == " D" )
You can’t perform that action at this time.
0 commit comments