Skip to content

Commit 91b33be

Browse files
committed
[auto import] fix Scala 3 enum case import suggestion #SCL-22747 fixed
1 parent a25a9e2 commit 91b33be

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

scala/scala-impl/src/org/jetbrains/plugins/scala/autoImport/quickFix/ScalaImportTypeFix.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile
1818
import org.jetbrains.plugins.scala.lang.psi.api.base.ScReference
1919
import org.jetbrains.plugins.scala.lang.psi.api.base.types.{ScSimpleTypeElement, ScTypeProjection}
2020
import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScMethodCall, ScSugarCallExpr}
21-
import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScTypeAlias}
21+
import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScEnumCase, ScFunction, ScTypeAlias}
2222
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.templates.ScTemplateBody
2323
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._
2424
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.{ScPackaging, ScTypedDefinition}
@@ -77,6 +77,7 @@ object ScalaImportTypeFix {
7777

7878
@annotation.tailrec
7979
private[this] def notInner(clazz: PsiClass, ref: PsiElement): Boolean = clazz match {
80+
case enumCase: ScEnumCase => notInner(enumCase.enumParent, ref)
8081
case o: ScObject if o.isSyntheticObject =>
8182
val companion = getCompanionModule(o)
8283
companion match {

scala/scala-impl/test/org/jetbrains/plugins/scala/lang/autoImport/ScalaImportTypeFixTest.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,4 +500,48 @@ class Scala3ImportTypeFixTest extends ScalaImportTypeFixTestBase {
500500
|""".stripMargin,
501501
"MyObject.MyEnumInClass"
502502
)
503+
504+
def testEnumSingletonCase(): Unit = {
505+
val fileText =
506+
s"""enum Source:
507+
| case Foo
508+
|
509+
|object Target:
510+
| val foo = ${CARET}Foo
511+
|""".stripMargin
512+
val qNameToImport = "Source.Foo"
513+
514+
checkElementsToImport(
515+
fileText,
516+
qNameToImport
517+
)
518+
519+
doTest(
520+
fileText,
521+
expectedText = s"import $qNameToImport\n\n${fileText.replace(CARET, "")}",
522+
selected = qNameToImport
523+
)
524+
}
525+
526+
def testEnumClassCase(): Unit = {
527+
val fileText =
528+
s"""enum Source:
529+
| case Foo(i: Int)
530+
|
531+
|object Target:
532+
| val foo = ${CARET}Foo(2)
533+
|""".stripMargin
534+
val qNameToImport = "Source.Foo"
535+
536+
checkElementsToImport(
537+
fileText,
538+
qNameToImport
539+
)
540+
541+
doTest(
542+
fileText,
543+
expectedText = s"import $qNameToImport\n\n${fileText.replace(CARET, "")}",
544+
selected = qNameToImport
545+
)
546+
}
503547
}

0 commit comments

Comments
 (0)