Skip to content

Commit

Permalink
[resolve] Fix edge cases in apply resolve
Browse files Browse the repository at this point in the history
(#SCL-23327, #SCL-23322) fixed
  • Loading branch information
sugakandrey authored and SrTobi committed Dec 17, 2024
1 parent 6545dd7 commit 2dcb6a0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,17 @@ class ScalaTypeParameterInfoHandler extends ScalaParameterInfoHandler[ScTypeArgs

private def fromResolved(ref: ScReference, useActualElement: Boolean = false): Option[(PsiElement, ScSubstitutor)] = {
ref.bind() match {
case Some(srr @ ScalaResolveResult.ApplyMethodInnerResolve(inner)) =>
val (elem, subst) =
if (inner.elementHasTypeParameters) (inner.element, inner.substitutor)
else (srr.element, srr.substitutor)

Option((elem, subst))
case Some(r @ ScalaResolveResult(m: PsiMethod, substitutor)) =>
val element = if (useActualElement) r.getActualElement else m
Some((element, substitutor))
Option((element, substitutor))
case Some(ScalaResolveResult(element @ (_: PsiClass | _: ScTypeParametersOwner), substitutor)) =>
Some((element, substitutor))
Option((element, substitutor))
case Some(srr) =>
srr.innerResolveResult.map(x => (x.getActualElement, x.substitutor))
case _ => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,12 @@ object MethodResolveProcessor {
if (r.name == CommonNames.Apply) {
//This is the case when previous shapeResolve has already extracted an apply method
//we still need to calculate if type args are relevant or not.
val originalElement = r.innerResolveResult.getOrElse(r).element
val (_, cleanTypeArgs) = invocationInfo(originalElement)
Set((r, cleanTypeArgs))
r.innerResolveResult match {
case None => Set((r, false))
case Some(innerSrr) =>
val (_, cleanTypeArgs) = invocationInfo(innerSrr.element)
Set((r, cleanTypeArgs))
}
} else if (argumentClauses.isEmpty && typeArgElements.isEmpty)
Set((r, false))
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class TypeParameterInfoSimpleTestsTest extends TypeParameterInfoTestBase {

def testApplyMethodA(): Unit = doTest()

// TODO
// def testApplyMethodB = doTest
def testApplyMethodB(): Unit = doTest()

def testApplyTypeParams(): Unit = doTest()

def testContravariant(): Unit = doTest()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ class CurriedTypeParamsApplyCallTest extends TypeInferenceTestBase {
|//Int => (String, Boolean)
|""".stripMargin
)

def testSCL23327(): Unit = doTest(
s"""
|object Main {
| trait IO[A]
| trait GenSpawn[F[_], E]
| trait Async[F[_]] extends GenSpawn[F, Throwable]
| def apply[F[_], E](implicit F: GenSpawn[F, E]): F.type = F
| def apply[F[_]](implicit F: GenSpawn[F, _], d: DummyImplicit): F.type = F
| implicit val x: Async[IO] = ???
|
| ${START}apply[IO]$END
|}
|//Main.Async[Main.IO]
|""".stripMargin
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object IO {
def partial[R]: MyPartiallyApplied[R] = ???
case class MyPartiallyApplied[R]() {
def apply[E, A](x: A) = ???
}

IO.partial[<caret>] { ??? }
}
//TEXT: R, STRIKEOUT: false

0 comments on commit 2dcb6a0

Please sign in to comment.