Skip to content

Commit 28d59a0

Browse files
committed
Assign types to type variables in match case types
1 parent fa4cb01 commit 28d59a0

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -420,19 +420,20 @@ class ExtractSemanticDB extends Phase:
420420
else
421421
val symkinds = mutable.HashSet.empty[SymbolKind]
422422
tree match
423-
case tree: ValDef =>
424-
if !tree.symbol.is(Param) then
425-
symkinds += (if tree.mods is Mutable then SymbolKind.Var else SymbolKind.Val)
426-
if tree.rhs.isEmpty && !tree.symbol.isOneOf(TermParam | CaseAccessor | ParamAccessor) then
427-
symkinds += SymbolKind.Abstract
428-
case tree: DefDef =>
429-
if tree.isSetterDef then
430-
symkinds += SymbolKind.Setter
431-
else if tree.rhs.isEmpty then
432-
symkinds += SymbolKind.Abstract
433-
case tree: Bind =>
434-
symkinds += SymbolKind.Val
435-
case _ =>
423+
case tree: ValDef =>
424+
if !tree.symbol.is(Param) then
425+
symkinds += (if tree.mods is Mutable then SymbolKind.Var else SymbolKind.Val)
426+
if tree.rhs.isEmpty && !tree.symbol.isOneOf(TermParam | CaseAccessor | ParamAccessor) then
427+
symkinds += SymbolKind.Abstract
428+
case tree: DefDef =>
429+
if tree.isSetterDef then
430+
symkinds += SymbolKind.Setter
431+
else if tree.rhs.isEmpty then
432+
symkinds += SymbolKind.Abstract
433+
// if symbol isType, it's type variable
434+
case tree: Bind if (!tree.symbol.isType) =>
435+
symkinds += SymbolKind.Val
436+
case _ =>
436437
symkinds.toSet
437438

438439
private def ctorParams(

compiler/src/dotty/tools/dotc/semanticdb/PPrint.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ class SymbolInformationPrinter (symtab: PrinterSymtab):
125125
if (tparams.infos.nonEmpty)
126126
sb.append(tparams.infos.map(pprintDef).mkString("[", ", ", "]"))
127127
if (lo == hi) {
128-
if (lo == Type.Empty) ()
129-
else sb.append(s" = ${pprint(lo)}")
128+
sb.append(s" = ${pprint(lo)}")
130129
} else {
131130
lo match
132131
case TypeRef(Type.Empty, "scala/Nothing#", Nil) => ()

compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ class TypeOps:
233233
val ssym = sym.symbolName
234234
s.TypeRef(spre, ssym, Seq.empty)
235235

236+
case TypeRef(pre, sym: Name) =>
237+
// val spre = if tpe.hasTrivialPrefix then s.Type.Empty else loop(pre)
238+
// Craft semanticdb symbol
239+
// prefix symbol (e.g. "scala/") + name (e.g. "Nothing") + Global symbol suffix ("#")
240+
// see: https://scalameta.org/docs/semanticdb/specification.html#symbol
241+
val ssym = s"${pre.typeSymbol.symbolName}${sym.mangledString}#"
242+
s.TypeRef(s.Type.Empty, ssym, Seq.empty)
243+
236244
case TermRef(pre, sym: Symbol) =>
237245
val spre = if(tpe.hasTrivialPrefix) s.Type.Empty else loop(pre)
238246
val ssym = sym.symbolName

tests/semanticdb/metac.expect

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,10 +2034,10 @@ example/MatchType$package.Concat#[Xs] => typeparam Xs <: Tuple
20342034
example/MatchType$package.Concat#[Ys] => covariant typeparam Ys <: Tuple
20352035
example/MatchType$package.Elem# => type Elem [typeparam X ] = X match { String => Char, Array[t] => t, Iterable[t] => t }
20362036
example/MatchType$package.Elem#[X] => typeparam X
2037-
local0 => case val method t
2038-
local1 => case val method t
2039-
local2 => case val method x
2040-
local3 => case val method xs
2037+
local0 => case type t
2038+
local1 => case type t
2039+
local2 => case type x
2040+
local3 => case type xs <: Tuple
20412041

20422042
Occurrences:
20432043
[0:8..0:15): example <- example/
@@ -4087,9 +4087,9 @@ Occurrences => 46 entries
40874087
Synthetics => 3 entries
40884088

40894089
Symbols:
4090-
local0 => case val method N$1 <: Nat
4090+
local0 => case type N$1 <: Nat
40914091
local1 => val local p: N$1
4092-
local2 => case val method N$2 <: Nat
4092+
local2 => case type N$2 <: Nat
40934093
local3 => val local p: N$2
40944094
local4 => val local Nat_this: Zero.type
40954095
local5 => val local Nat_this: Succ[Zero.type]
@@ -4271,7 +4271,7 @@ flags/p/package.y(). => protected implicit var method y Int
42714271
flags/p/package.z(). => method z (param pp: Int): Int
42724272
flags/p/package.z().(pp) => param pp: Int
42734273
local0 => val local xs2: Nothing
4274-
local1 => case val method t
4274+
local1 => case type t
42754275

42764276
Occurrences:
42774277
[0:8..0:13): flags <- flags/

0 commit comments

Comments
 (0)