Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Case completions in summonFrom #6241

Merged
merged 1 commit into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,6 +26,7 @@ import dotty.tools.dotc.core.Symbols.NoSymbol
import dotty.tools.dotc.core.Symbols.Symbol
import dotty.tools.dotc.core.Types.AndType
import dotty.tools.dotc.core.Types.ClassInfo
import dotty.tools.dotc.core.Types.NoType
import dotty.tools.dotc.core.Types.OrType
import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.core.Types.TypeRef
Expand Down Expand Up @@ -94,7 +95,7 @@ object CaseKeywordCompletion:
Some(sel.tpe.widen.metalsDealias)

selTpe
.map { selTpe =>
.collect { case selTpe if selTpe != NoType =>
val selectorSym = selTpe.typeSymbol
// Special handle case when selector is a tuple or `FunctionN`.
if definitions.isTupleClass(selectorSym) || definitions.isFunctionClass(
Expand Down
33 changes: 33 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionCaseSuite.scala
Expand Up @@ -833,4 +833,37 @@ class CompletionCaseSuite extends BaseCompletionSuite {
filter = _.contains("exhaustive")
)

check(
"summonFrom".tag(IgnoreScala2),
"""
|object A {
| import scala.compiletime.summonFrom
| class A
|
| inline def f: Any = summonFrom {
| case x@@: A => ??? // error: ambiguous givens
| }
|}
|""".stripMargin,
""
)

check(
"summonFrom1".tag(IgnoreScala2),
"""
|object A {
| import scala.compiletime.summonFrom
|
| class A
| given a1: A = new A
| given a2: A = new A
|
| inline def f: Any = summonFrom {
| case x@@: A => ??? // error: ambiguous givens
| }
|}
|""".stripMargin,
""
)

}