Skip to content

Commit c3b1660

Browse files
committed
Assume special capturing types for eq and ne
They take a `{*} Object` instead of an `Object` parameter.
1 parent f062160 commit c3b1660

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

compiler/src/dotty/tools/dotc/cc/Synthetics.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ object Synthetics:
3131
* The types of these symbols are transformed in a special way without
3232
* looking at the definitions's RHS
3333
*/
34-
def needsTransform(sym: SymDenotation)(using Context): Boolean =
35-
isSyntheticCopyMethod(sym)
36-
|| isSyntheticCompanionMethod(sym, nme.apply, nme.unapply)
37-
|| isSyntheticCopyDefaultGetterMethod(sym)
34+
def needsTransform(symd: SymDenotation)(using Context): Boolean =
35+
isSyntheticCopyMethod(symd)
36+
|| isSyntheticCompanionMethod(symd, nme.apply, nme.unapply)
37+
|| isSyntheticCopyDefaultGetterMethod(symd)
38+
|| (symd.symbol eq defn.Object_eq)
39+
|| (symd.symbol eq defn.Object_ne)
3840

3941
/** Method is excluded from regular capture checking.
4042
* Excluded are synthetic class members
@@ -166,7 +168,9 @@ object Synthetics:
166168
sym.copySymDenotation(info = addUnapplyCaptures(sym.info))
167169
case nme.apply | nme.copy =>
168170
sym.copySymDenotation(info = addCaptureDeps(sym.info))
169-
171+
case n if n == nme.eq || n == nme.ne =>
172+
sym.copySymDenotation(info =
173+
MethodType(defn.ObjectType.capturing(CaptureSet.universal) :: Nil, defn.BooleanType))
170174

171175
/** If `sym` refers to a synthetic apply, unapply, copy, or copy default getter method
172176
* of a case class, transform it back to what it was before the CC phase.
@@ -179,5 +183,7 @@ object Synthetics:
179183
sym.copySymDenotation(info = dropUnapplyCaptures(sym.info))
180184
case nme.apply | nme.copy =>
181185
sym.copySymDenotation(info = dropCaptureDeps(sym.info))
186+
case n if n == nme.eq || n == nme.ne =>
187+
sym.copySymDenotation(info = defn.methOfAnyRef(defn.BooleanType))
182188

183189
end Synthetics

0 commit comments

Comments
 (0)