Skip to content

Commit

Permalink
Consider extension methods in Space isSameUnapply
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 3, 2023
1 parent de4ad2b commit fdb361f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,14 @@ object SpaceEngine {
* We assume that unapply methods are pure, but the same method may
* be called with different prefixes, thus behaving differently.
*/
def isSameUnapply(tp1: TermRef, tp2: TermRef)(using Context): Boolean =
def isSameUnapply(tp1: TermRef, tp2: TermRef)(using Context): Boolean = trace(i"isSameUnapply($tp1, $tp2)") {
def isStable(tp: TermRef) =
!tp.symbol.is(ExtensionMethod) // The "prefix" of an extension method may be, but the receiver isn't, so exclude
&& tp.prefix.isStable
// always assume two TypeTest[S, T].unapply are the same if they are equal in types
(tp1.prefix.isStable && tp2.prefix.isStable || tp1.symbol == defn.TypeTest_unapply)
(isStable(tp1) && isStable(tp2) || tp1.symbol == defn.TypeTest_unapply)
&& tp1 =:= tp2
}

/** Return term parameter types of the extractor `unapp`.
* Parameter types of the case class type `tp`. Adapted from `unapplyPlan` in patternMatcher */
Expand Down

0 comments on commit fdb361f

Please sign in to comment.