Repository: scalacenter/tasty-query (scala)

Issue:
`Symbol.matchingSymbol` returns wrong symbol
```scala
trait A:
  def m(x: Int): Boolean = ???

class B extends A:
  def m: Boolean
```

Using TASTy Query:
```scala
val classB = ??? // symbol[class B]
val mInTraitA = ??? // symbol[trait A.m]
mInTraitA.matchingSymbol(classB, classB).get // symbol[class B.m]
```

The returned matching symbol is incorrect, it should return `symbol[trait A.m]`.

Pull request description:
fixes #374

Patch:
diff --git a/tasty-query/shared/src/main/scala/tastyquery/TypeOps.scala b/tasty-query/shared/src/main/scala/tastyquery/TypeOps.scala
index caa04660..9b57b0e4 100644
--- a/tasty-query/shared/src/main/scala/tastyquery/TypeOps.scala
+++ b/tasty-query/shared/src/main/scala/tastyquery/TypeOps.scala
@@ -110,7 +110,8 @@ private[tastyquery] object TypeOps:
         case _: PolyType =>
           false
         case tp2: MethodType =>
-          matchesType(tp1, tp2.resultType)
+          tp2.paramNames.isEmpty
+            && matchesType(tp1, tp2.resultType)
         case _ =>
           true
   end matchesType


Test patch:
diff --git a/tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala b/tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala
index 8f3e03e0..d1a0ec3d 100644
--- a/tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala
+++ b/tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala
@@ -1803,6 +1803,12 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
     val poly1InChild = polyInChild.find(_.typeParamCountIs(1)).get
     val poly2InChild = polyInChild.find(_.typeParamCountIs(2)).get
 
+    val overloadedParensNoParensInSuper = SuperMonoClass.findNonOverloadedDecl(termName("overloadedParensNoParens"))
+    val overloadedParensNoParensInChild = ChildMonoClass.findNonOverloadedDecl(termName("overloadedParensNoParens"))
+
+    val overloadedNoParensParensInSuper = SuperMonoClass.findNonOverloadedDecl(termName("overloadedNoParensParens"))
+    val overloadedNoParensParensInChild = ChildMonoClass.findNonOverloadedDecl(termName("overloadedNoParensParens"))
+
     // From intInSuper
 
     assert(clue(intInSuper.overriddenSymbol(SuperMonoClass)) == Some(intInSuper))
@@ -1922,6 +1928,82 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
 
     assert(clue(poly2InChild.allOverriddenSymbols.toList) == List(poly2InSuper))
     assert(clue(poly2InChild.nextOverriddenSymbol) == Some(poly2InSuper))
+
+    // From overloadedParensNoParensInSuper
+
+    assert(
+      clue(overloadedParensNoParensInSuper.overriddenSymbol(SuperMonoClass)) == Some(overloadedParensNoParensInSuper)
+    )
+    assert(clue(overloadedParensNoParensInSuper.overriddenSymbol(ChildMonoClass)) == None)
+
+    assert(
+      clue(overloadedParensNoParensInSuper.overridingSymbol(SuperMonoClass)) == Some(overloadedParensNoParensInSuper)
+    )
+    assert(clue(overloadedParensNoParensInSuper.overridingSymbol(ChildMonoClass)) == None)
+
+    assert(
+      clue(overloadedParensNoParensInSuper.matchingSymbol(SuperMonoClass, ChildMonoClass)) == Some(
+        overloadedParensNoParensInSuper
+      )
+    )
+    assert(clue(overloadedParensNoParensInSuper.matchingSymbol(ChildMonoClass, ChildMonoClass)) == None)
+
+    // From overloadedParensNoParensInChild
+
+    assert(clue(overloadedParensNoParensInChild.overriddenSymbol(SuperMonoClass)) == None)
+    assert(
+      clue(overloadedParensNoParensInChild.overriddenSymbol(ChildMonoClass)) == Some(overloadedParensNoParensInChild)
+    )
+
+    assert(clue(overloadedParensNoParensInChild.overridingSymbol(SuperMonoClass)) == None)
+    assert(
+      clue(overloadedParensNoParensInChild.overridingSymbol(ChildMonoClass)) == Some(overloadedParensNoParensInChild)
+    )
+
+    assert(clue(overloadedParensNoParensInChild.matchingSymbol(SuperMonoClass, ChildMonoClass)) == None)
+    assert(
+      clue(overloadedParensNoParensInChild.matchingSymbol(ChildMonoClass, ChildMonoClass)) == Some(
+        overloadedParensNoParensInChild
+      )
+    )
+
+    // From overloadedNoParensParensInSuper
+
+    assert(
+      clue(overloadedNoParensParensInSuper.overriddenSymbol(SuperMonoClass)) == Some(overloadedNoParensParensInSuper)
+    )
+    assert(clue(overloadedNoParensParensInSuper.overriddenSymbol(ChildMonoClass)) == None)
+
+    assert(
+      clue(overloadedNoParensParensInSuper.overridingSymbol(SuperMonoClass)) == Some(overloadedNoParensParensInSuper)
+    )
+    assert(clue(overloadedNoParensParensInSuper.overridingSymbol(ChildMonoClass)) == None)
+
+    assert(
+      clue(overloadedNoParensParensInSuper.matchingSymbol(SuperMonoClass, ChildMonoClass)) == Some(
+        overloadedNoParensParensInSuper
+      )
+    )
+    assert(clue(overloadedNoParensParensInSuper.matchingSymbol(ChildMonoClass, ChildMonoClass)) == None)
+
+    // From overloadedNoParensParensInChild
+
+    assert(clue(overloadedNoParensParensInChild.overriddenSymbol(SuperMonoClass)) == None)
+    assert(
+      clue(overloadedNoParensParensInChild.overriddenSymbol(ChildMonoClass)) == Some(overloadedNoParensParensInChild)
+    )
+
+    assert(clue(overloadedNoParensParensInChild.overridingSymbol(SuperMonoClass)) == None)
+    assert(
+      clue(overloadedNoParensParensInChild.overridingSymbol(ChildMonoClass)) == Some(overloadedNoParensParensInChild)
+    )
+
+    assert(clue(overloadedNoParensParensInChild.matchingSymbol(SuperMonoClass, ChildMonoClass)) == None)
+    assert(
+      clue(overloadedNoParensParensInChild.matchingSymbol(ChildMonoClass, ChildMonoClass)) == Some(
+        overloadedNoParensParensInChild
+      )
+    )
   }
 
   testWithContext("overrides-cannot-override") {
diff --git a/test-sources/src/main/scala/inheritance/Overrides.scala b/test-sources/src/main/scala/inheritance/Overrides.scala
index 6de73c7c..e417fcd0 100644
--- a/test-sources/src/main/scala/inheritance/Overrides.scala
+++ b/test-sources/src/main/scala/inheritance/Overrides.scala
@@ -13,6 +13,10 @@ object Overrides:
     def overloadedPoly[A](x: A): A = x
     def overloadedPoly[A, B](x: A, y: B): (A, B) = (x, y)
 
+    def overloadedParensNoParens(x: Int): Int = x
+
+    def overloadedNoParensParens: Int = 1
+
     override def toString(): String = "SuperMono"
   end SuperMono
 
@@ -34,6 +38,10 @@ object Overrides:
     override def overloadedPoly[B](a: B): B = a
     override def overloadedPoly[X, B](x: X, y: B): (X, B) = (x, y)
 
+    def overloadedParensNoParens: Int = 1
+
+    def overloadedNoParensParens(x: Int): Int = x
+
     override def toString: String = "ChildMono"
   end ChildMono