From 5092e8cac8929b77751ced8409e9178ef01c6ec1 Mon Sep 17 00:00:00 2001 From: Andrei Sugak Date: Mon, 18 Nov 2024 10:01:04 +0000 Subject: [PATCH 1/2] [resolve] Fix edge cases in apply resolve (#SCL-23327, #SCL-23322) fixed --- .../ScalaTypeParameterInfoHandler.scala | 10 ++++++++-- .../processor/MethodResolveProcessor.scala | 9 ++++++--- .../TypeParameterInfoSimpleTestsTest.scala | 5 +++-- .../CurriedTypeParamsApplyCallTest.scala | 16 ++++++++++++++++ .../SimpleTests/ApplyTypeParams.scala | 9 +++++++++ 5 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 scala/scala-impl/testdata/parameterInfo/typeParameterInfo/SimpleTests/ApplyTypeParams.scala diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaTypeParameterInfoHandler.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaTypeParameterInfoHandler.scala index a0e380bf7d9..00b7c1969d3 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaTypeParameterInfoHandler.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parameterInfo/ScalaTypeParameterInfoHandler.scala @@ -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 diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala index 7415408a4d7..4dc473a9e4f 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/resolve/processor/MethodResolveProcessor.scala @@ -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 { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/parameterInfo/typeParameterInfo/TypeParameterInfoSimpleTestsTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/parameterInfo/typeParameterInfo/TypeParameterInfoSimpleTestsTest.scala index 25daa4c1aff..9a515289dcb 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/parameterInfo/typeParameterInfo/TypeParameterInfoSimpleTestsTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/parameterInfo/typeParameterInfo/TypeParameterInfoSimpleTestsTest.scala @@ -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() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/CurriedTypeParamsApplyCallTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/CurriedTypeParamsApplyCallTest.scala index 740370ad465..d8e080c9d6e 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/CurriedTypeParamsApplyCallTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/typeInference/CurriedTypeParamsApplyCallTest.scala @@ -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 + ) } diff --git a/scala/scala-impl/testdata/parameterInfo/typeParameterInfo/SimpleTests/ApplyTypeParams.scala b/scala/scala-impl/testdata/parameterInfo/typeParameterInfo/SimpleTests/ApplyTypeParams.scala new file mode 100644 index 00000000000..762cfc163b8 --- /dev/null +++ b/scala/scala-impl/testdata/parameterInfo/typeParameterInfo/SimpleTests/ApplyTypeParams.scala @@ -0,0 +1,9 @@ +object IO { + def partial[R]: MyPartiallyApplied[R] = ??? + case class MyPartiallyApplied[R]() { + def apply[E, A](x: A) = ??? + } + + IO.partial[] { ??? } +} +//TEXT: R, STRIKEOUT: false \ No newline at end of file From 3d8273b9ae8d168a9f246e785a125e31904215dd Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Tue, 17 Dec 2024 15:44:30 +0100 Subject: [PATCH 2/2] [cbh] Do not suppress Java highlighting by default when Compiler error highlighting is enabled #SCL-19340 fixed --- scala/scala-impl/resources/META-INF/scala-plugin-common.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml index 5e5f2a96be0..4015cf86689 100644 --- a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml +++ b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml @@ -642,7 +642,7 @@ -