Skip to content

Commit d4fc495

Browse files
committed
SCL-23859: show kind mismatch error for existential types
1 parent 43e22fc commit d4fc495

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

scala/scala-impl/src/org/jetbrains/plugins/scala/annotator/element/ScParameterizedTypeElementAnnotator.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ object ScParameterizedTypeElementAnnotator extends ElementAnnotator[ScParameteri
139139
(arg, param) <- args.zip(params)
140140
argTy <- getType(arg).toOption
141141
range = if (isForContextBound) annotationRange else arg.getTextRange
142-
if !argTy.is[ScExistentialArgument, ScExistentialType] &&
143-
!argIsDesignatedToTypeVariable(arg) &&
142+
if !argIsDesignatedToTypeVariable(arg) &&
144143
!KindProjectorUtil.syntaxIdsFor(arg).contains(arg.getText)
145144
} {
146-
checkBounds(range, argTy, param, substitute)
145+
if(!argTy.is[ScExistentialArgument, ScExistentialType]) checkBounds(range, argTy, param, substitute)
147146
checkHigherKindedType(range, argTy, param, substitute)
148147
}
149148
}

scala/scala-impl/test/org/jetbrains/plugins/scala/annotator/ScGenericCallAnnotatorTest.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class ScGenericCallAnnotatorTest extends SimpleTestCase {
6060
assertMessages(messages("testHk[HkArg]"))(
6161
Error("HkArg", "Type constructor HkArg does not conform to CC[X >: B <: B, _]")
6262
)
63+
64+
assertMessages(messages("class Test[X, Y]; testHk[Test[_, _]]"))(
65+
Error("Test[_, _]", "Expected type constructor CC[X >: B <: B, _]")
66+
)
6367
}
6468

6569
def testTypeConstructorParameter(): Unit = {

scala/scala-impl/test/org/jetbrains/plugins/scala/annotator/ScParameterizedTypeElementAnnotatorTest.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ class ScParameterizedTypeElementAnnotatorTest_scala_2 extends ScParameterizedTyp
227227
))
228228
}
229229

230+
def testExistentialTypeKindMismatch(): Unit = {
231+
assertMessages(messages(
232+
"""
233+
|class Option[A]
234+
|class TestClass[F[_]]
235+
|
236+
|def test: TestClass[Option[_]] = ???
237+
|""".stripMargin
238+
))(
239+
Error("Option[_]", "Expected type constructor F[_]")
240+
)
241+
}
242+
230243
def testUnresolved(): Unit = {
231244
assertNothing(messages(
232245
"""

0 commit comments

Comments
 (0)