File tree 3 files changed +115
-3
lines changed
src/main/dotty/tools/pc/completions
test/dotty/tools/pc/tests/completion
3 files changed +115
-3
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ object CaseKeywordCompletion:
90
90
new Parents (NoType , definitions)
91
91
case sel => new Parents (sel.tpe, definitions)
92
92
93
- val selectorSym = parents.selector.typeSymbol
93
+ val selectorSym = parents.selector.widen.metalsDealias. typeSymbol
94
94
95
95
// Special handle case when selector is a tuple or `FunctionN`.
96
96
if definitions.isTupleClass(selectorSym) || definitions.isFunctionClass(
@@ -153,7 +153,9 @@ object CaseKeywordCompletion:
153
153
if isValid(ts) then visit(autoImportsGen.inferSymbolImport(ts))
154
154
)
155
155
// Step 2: walk through known subclasses of sealed types.
156
- val sealedDescs = subclassesForType(parents.selector.widen.bounds.hi)
156
+ val sealedDescs = subclassesForType(
157
+ parents.selector.widen.metalsDealias.bounds.hi
158
+ )
157
159
sealedDescs.foreach { sym =>
158
160
val symbolImport = autoImportsGen.inferSymbolImport(sym)
159
161
visit(symbolImport)
@@ -241,7 +243,7 @@ object CaseKeywordCompletion:
241
243
completionPos,
242
244
clientSupportsSnippets
243
245
)
244
- val tpe = selector.tpe.widen.bounds.hi match
246
+ val tpe = selector.tpe.widen.metalsDealias. bounds.hi match
245
247
case tr @ TypeRef (_, _) => tr.underlying
246
248
case t => t
247
249
Original file line number Diff line number Diff line change @@ -657,3 +657,44 @@ class CompletionCaseSuite extends BaseCompletionSuite:
657
657
|case Singing(song) => test.Activity
658
658
|case Sports(time, intensity) => test.Activity""" .stripMargin
659
659
)
660
+
661
+ @ Test def `type-alias-case` =
662
+ check(
663
+ s """ |object O:
664
+ | type Id[A] = A
665
+ |
666
+ | enum Animal:
667
+ | case Cat, Dog
668
+ |
669
+ | val animal: Id[Animal] = ???
670
+ |
671
+ | animal match
672
+ | cas@@
673
+ | """ .stripMargin,
674
+ """ |case Animal.Cat =>
675
+ |case Animal.Dog =>
676
+ |""" .stripMargin,
677
+ )
678
+
679
+ @ Test def `type-alias-sealed-trait-case` =
680
+ check(
681
+ s """ |object O {
682
+ | type Id[A] = A
683
+ |
684
+ |sealed trait Animal
685
+ |object Animal {
686
+ | case class Cat() extends Animal
687
+ | case object Dog extends Animal
688
+ |}
689
+ |
690
+ | val animal: Id[Animal] = ???
691
+ |
692
+ | animal match {
693
+ | cas@@
694
+ | }
695
+ |}
696
+ | """ .stripMargin,
697
+ """ |case Cat() => test.O.Animal
698
+ |case Dog => test.O.Animal
699
+ |""" .stripMargin,
700
+ )
Original file line number Diff line number Diff line change @@ -601,3 +601,72 @@ class CompletionMatchSuite extends BaseCompletionSuite:
601
601
|} """ .stripMargin,
602
602
filter = _.contains(" exhaustive" )
603
603
)
604
+
605
+ @ Test def `type-alias` =
606
+ checkEdit(
607
+ s """ |object O {
608
+ | type Id[A] = A
609
+ |
610
+ | enum Animal:
611
+ | case Cat, Dog
612
+ |
613
+ | val animal: Id[Animal] = ???
614
+ |
615
+ | animal ma@@
616
+ |}
617
+ | """ .stripMargin,
618
+ s """ object O {
619
+ | type Id[A] = A
620
+ |
621
+ | enum Animal:
622
+ | case Cat, Dog
623
+ |
624
+ | val animal: Id[Animal] = ???
625
+ |
626
+ | animal match
627
+ |\tcase Animal.Cat => $$ 0
628
+ |\tcase Animal.Dog =>
629
+ |
630
+ |}
631
+ | """ .stripMargin,
632
+ filter = _.contains(" exhaustive" ),
633
+ )
634
+
635
+ @ Test def `type-alias-sealed-trait` =
636
+ checkEdit(
637
+ s """ |object O {
638
+ | type Id[A] = A
639
+ |
640
+ |sealed trait Animal
641
+ |object Animal {
642
+ | case object Cat extends Animal
643
+ | case object Dog extends Animal
644
+ |}
645
+ |
646
+ | val animal: Id[Animal] = ???
647
+ |
648
+ |animal ma@@
649
+ |}
650
+ | """ .stripMargin,
651
+ s """ |
652
+ |import O.Animal.Cat
653
+ |import O.Animal.Dog
654
+ |object O {
655
+ | type Id[A] = A
656
+ |
657
+ |sealed trait Animal
658
+ |object Animal {
659
+ | case object Cat extends Animal
660
+ | case object Dog extends Animal
661
+ |}
662
+ |
663
+ | val animal: Id[Animal] = ???
664
+ |
665
+ |animal match
666
+ |\tcase Cat => $$ 0
667
+ |\tcase Dog =>
668
+ |
669
+ |}
670
+ | """ .stripMargin,
671
+ filter = _.contains(" exhaustive" ),
672
+ )
You can’t perform that action at this time.
0 commit comments