Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #374: Fix matchesType between MethodType and Type. #375

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tasty-query/shared/src/main/scala/tastyquery/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 82 additions & 0 deletions tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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") {
Expand Down
8 changes: 8 additions & 0 deletions test-sources/src/main/scala/inheritance/Overrides.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down