Skip to content

Commit 95af95c

Browse files
committed
Make wildcard type symbol global
1 parent 3496704 commit 95af95c

File tree

8 files changed

+37
-36
lines changed

8 files changed

+37
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object Scala3:
3535
* - name: local...
3636
* - SymbolInformation with signature TypeSignature of given type bound.
3737
*/
38-
case class WildcardTypeSymbol(bounds: TypeBounds) extends FakeSymbol
38+
case class WildcardTypeSymbol(owner: Symbol, bounds: TypeBounds) extends FakeSymbol
3939
case class TypeParamRefSymbol(owner: Symbol, name: Name, tp: TypeBounds) extends FakeSymbol
4040
type SemanticSymbol = Symbol | FakeSymbol
4141
extension (sym: SemanticSymbol)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ class SemanticSymbolBuilder:
3131
b.toString
3232
def symbolName(sym: FakeSymbol)(using Context): String =
3333
sym match
34-
case _: WildcardTypeSymbol =>
35-
val idx = nextLocalIdx
36-
nextLocalIdx += 1
37-
s"${Symbols.LocalPrefix}${idx}"
34+
case sym: WildcardTypeSymbol =>
35+
val b = StringBuilder(20)
36+
addSymName(b, sym.owner)
37+
b.append('['); addName(b, sym.name); b.append(']')
38+
b.toString
3839
case sym: TypeParamRefSymbol =>
3940
val b = StringBuilder(20)
4041
addSymName(b, sym.owner)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class TypeOps:
183183
val paramSyms: List[SemanticSymbol] = lambda.paramNames.zip(lambda.paramInfos).flatMap { (paramName, bounds) =>
184184
// def x[T[_]] = ???
185185
if paramName.isWildcard then
186-
Some(WildcardTypeSymbol(bounds))
186+
Some(WildcardTypeSymbol(sym, bounds))
187187
else
188188
val found = paramRefSymtab.lookup(lambda, paramName, sym)
189189
if found.exists then
@@ -343,7 +343,7 @@ class TypeOps:
343343
// display_name: "_" and,
344344
// signature: type_signature(..., lo = <Nothing>, hi = <T>)
345345
case bounds: TypeBounds =>
346-
val wildcardSym = WildcardTypeSymbol(bounds)
346+
val wildcardSym = WildcardTypeSymbol(sym, bounds)
347347
val ssym = wildcardSym.symbolName
348348
(Some(wildcardSym), s.TypeRef(s.Type.Empty, ssym, Seq.empty))
349349
case other =>

tests/semanticdb/expect/Advanced.expect.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ object Test/*<-advanced::Test.*/ {
3636

3737
{
3838
(???/*->scala::Predef.`???`().*/ : Any/*->scala::Any#*/) match {
39-
case e3/*<-local15*/: List/*->scala::package.List#*/[_] =>
40-
val e3x/*<-local17*/ = e3/*->local15*/.head/*->scala::collection::IterableOps#head().*/
39+
case e3/*<-local12*/: List/*->scala::package.List#*/[_] =>
40+
val e3x/*<-local14*/ = e3/*->local12*/.head/*->scala::collection::IterableOps#head().*/
4141
()
4242
}
4343
}

tests/semanticdb/expect/Anonymous.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Anonymous/*<-example::Anonymous#*/ {
1212
???/*->scala::Predef.`???`().*/ match { case _: List/*->scala::package.List#*/[_] => }
1313
}
1414
locally/*->example::Anonymous#locally().*/ {
15-
val x/*<-local3*/: Int/*->scala::Int#*/ => Int/*->scala::Int#*/ = _ => ???/*->scala::Predef.`???`().*/
15+
val x/*<-local0*/: Int/*->scala::Int#*/ => Int/*->scala::Int#*/ = _ => ???/*->scala::Predef.`???`().*/
1616
}
1717

1818
trait Foo/*<-example::Anonymous#Foo#*/

tests/semanticdb/expect/Enums.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object Enums/*<-_empty_::Enums.*/:
5050
given /*<-_empty_::Enums.`<:<`.`given_<:<_T_T`().*/[T/*<-_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*/]: (T/*->_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*/ <:</*->_empty_::Enums.`<:<`#*/ T/*->_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*/) = Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.apply().*/()
5151

5252
extension [A/*<-_empty_::Enums.unwrap().[A]*/, B/*<-_empty_::Enums.unwrap().[B]*/](opt/*<-_empty_::Enums.unwrap().(opt)*/: Option/*->scala::Option#*/[A/*->_empty_::Enums.unwrap().[A]*/]) def unwrap/*<-_empty_::Enums.unwrap().*/(using ev/*<-_empty_::Enums.unwrap().(ev)*/: A/*->_empty_::Enums.unwrap().[A]*/ <:</*->_empty_::Enums.`<:<`#*/ Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]): Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/] = ev/*->_empty_::Enums.unwrap().(ev)*/ match
53-
case Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.unapply().*/() => opt/*->_empty_::Enums.unwrap().(opt)*/.flatMap/*->scala::Option#flatMap().*/(identity/*->scala::Predef.identity().*//*->local7*/[Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]])
53+
case Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.unapply().*/() => opt/*->_empty_::Enums.unwrap().(opt)*/.flatMap/*->scala::Option#flatMap().*/(identity/*->scala::Predef.identity().*//*->local0*/[Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]])
5454

5555
val some1/*<-_empty_::Enums.some1.*/ = Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1)).unwrap/*->_empty_::Enums.unwrap().*//*->_empty_::Enums.`<:<`.`given_<:<_T_T`().*/
5656

tests/semanticdb/expect/semanticdb-Types.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ object Test/*<-types::Test.*/ {
7474
val existentialType4/*<-types::Test.C#existentialType4.*/ = Class/*->java::lang::Class#*/.forName/*->java::lang::Class#forName().*/("foo.Bar")
7575

7676
def typeLambda1/*<-types::Test.C#typeLambda1().*/[M/*<-types::Test.C#typeLambda1().[M]*/[_]] = ???/*->scala::Predef.`???`().*/
77-
typeLambda1/*->types::Test.C#typeLambda1().*/[({ type L/*<-local15*/[T/*<-local14*/] = List/*->scala::package.List#*/[T/*->local14*/] })#L]
77+
typeLambda1/*->types::Test.C#typeLambda1().*/[({ type L/*<-local11*/[T/*<-local10*/] = List/*->scala::package.List#*/[T/*->local10*/] })#L]
7878

7979
object ClassInfoType1/*<-types::Test.C#ClassInfoType1.*/
8080
class ClassInfoType2/*<-types::Test.C#ClassInfoType2#*/ extends B/*->types::B#*/ { def x/*<-types::Test.C#ClassInfoType2#x().*/ = 42 }

tests/semanticdb/metac.expect

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ local7 => param x: Int
9696
local8 => method m (param x: Int): Int
9797
local9 => final class $anon extends Object { self: $anon => +2 decls }
9898
local11 => abstract val method x Int
99-
local15 => val local e3: List[local16]
100-
local17 => val local e3x: local16
99+
local12 => val local e3: List[local13]
100+
local14 => val local e3x: local13
101101

102102
Occurrences:
103103
[0:8..0:16): advanced <- advanced/
@@ -195,10 +195,10 @@ Occurrences:
195195
[34:17..34:21): head -> scala/collection/IterableOps#head().
196196
[37:5..37:8): ??? -> scala/Predef.`???`().
197197
[37:11..37:14): Any -> scala/Any#
198-
[38:11..38:13): e3 <- local15
198+
[38:11..38:13): e3 <- local12
199199
[38:15..38:19): List -> scala/package.List#
200-
[39:12..39:15): e3x <- local17
201-
[39:18..39:20): e3 -> local15
200+
[39:12..39:15): e3x <- local14
201+
[39:18..39:20): e3 -> local12
202202
[39:21..39:25): head -> scala/collection/IterableOps#head().
203203
[47:6..47:13): HKClass <- advanced/HKClass#
204204
[47:13..47:13): <- advanced/HKClass#`<init>`().
@@ -323,11 +323,11 @@ example/Anonymous#foo. => val method foo Foo
323323
example/Anonymous#locally(). => method locally [typeparam A ](param x: A): A
324324
example/Anonymous#locally().(x) => param x: A
325325
example/Anonymous#locally().[A] => typeparam A
326-
example/Anonymous#m1(). => method m1 [typeparam T [unknown local0: <?>]]: Nothing
327-
example/Anonymous#m1().[T] => typeparam T [unknown local0: <?>]
326+
example/Anonymous#m1(). => method m1 [typeparam T [unknown _: <?>]]: Nothing
327+
example/Anonymous#m1().[T] => typeparam T [unknown _: <?>]
328328
example/Anonymous#m2(). => method m2 => Map[_, List[_] forSome { type _ }] forSome { type _ }
329-
local3 => val local x: Function1[Int, Int]
330-
local4 => final class $anon extends Object with Foo { self: $anon => +1 decls }
329+
local0 => val local x: Function1[Int, Int]
330+
local1 => final class $anon extends Object with Foo { self: $anon => +1 decls }
331331

332332
Occurrences:
333333
[0:8..0:15): example <- example/
@@ -354,7 +354,7 @@ Occurrences:
354354
[11:4..11:7): ??? -> scala/Predef.`???`().
355355
[11:24..11:28): List -> scala/package.List#
356356
[13:2..13:9): locally -> example/Anonymous#locally().
357-
[14:8..14:9): x <- local3
357+
[14:8..14:9): x <- local0
358358
[14:11..14:14): Int -> scala/Int#
359359
[14:18..14:21): Int -> scala/Int#
360360
[14:29..14:32): ??? -> scala/Predef.`???`().
@@ -1038,7 +1038,7 @@ _empty_/Enums.unwrap().(ev) => implicit param ev: <:<[A, Option[B]]
10381038
_empty_/Enums.unwrap().(opt) => param opt: Option[A]
10391039
_empty_/Enums.unwrap().[A] => typeparam A
10401040
_empty_/Enums.unwrap().[B] => typeparam B
1041-
local7 => param x: Option[B]
1041+
local0 => param x: Option[B]
10421042

10431043
Occurrences:
10441044
[0:7..0:12): Enums <- _empty_/Enums.
@@ -1167,7 +1167,7 @@ Occurrences:
11671167
[52:19..52:22): opt -> _empty_/Enums.unwrap().(opt)
11681168
[52:23..52:30): flatMap -> scala/Option#flatMap().
11691169
[52:31..52:39): identity -> scala/Predef.identity().
1170-
[52:31..52:31): -> local7
1170+
[52:31..52:31): -> local0
11711171
[52:40..52:46): Option -> scala/Option#
11721172
[52:47..52:48): B -> _empty_/Enums.unwrap().[B]
11731173
[54:6..54:11): some1 <- _empty_/Enums.some1.
@@ -1325,9 +1325,9 @@ ext/Extension$package.readInto(). => method readInto [typeparam T ](param s: Str
13251325
ext/Extension$package.readInto().(s) => param s: String
13261326
ext/Extension$package.readInto().(x$2) => implicit param x$2: Read[T]
13271327
ext/Extension$package.readInto().[T] => typeparam T
1328-
ext/Functor# => trait Functor [typeparam F [unknown local0: <?>]] extends Object { self: Functor[F] => +3 decls }
1329-
ext/Functor#[F] => typeparam F [unknown local0: <?>]
1330-
ext/Functor#`<init>`(). => primary ctor <init> [typeparam F [unknown local0: <?>]](): Functor[F]
1328+
ext/Functor# => trait Functor [typeparam F [unknown _: <?>]] extends Object { self: Functor[F] => +3 decls }
1329+
ext/Functor#[F] => typeparam F [unknown _: <?>]
1330+
ext/Functor#`<init>`(). => primary ctor <init> [typeparam F [unknown _: <?>]](): Functor[F]
13311331
ext/Functor#map(). => abstract method map [typeparam T , typeparam U ](param t: F[T])(param f: Function1[T, U]): F[U]
13321332
ext/Functor#map().(f) => param f: Function1[T, U]
13331333
ext/Functor#map().(t) => param t: F[T]
@@ -4381,8 +4381,8 @@ local3 => final class $anon extends Object { self: $anon => +2 decls }
43814381
local5 => final class $anon extends M with N { self: $anon => +1 decls }
43824382
local7 => method k => Int
43834383
local8 => final class $anon extends M with N { self: $anon => +2 decls }
4384-
local14 => typeparam T
4385-
local15 => type L [typeparam T ] = List[T]
4384+
local10 => typeparam T
4385+
local11 => type L [typeparam T ] = List[T]
43864386
types/B# => class B extends Object { self: B => +1 decls }
43874387
types/B#`<init>`(). => primary ctor <init> (): B
43884388
types/C# => class C extends Object { self: C => +1 decls }
@@ -4460,8 +4460,8 @@ types/Test.C#TypeType.T5# => type T5 [typeparam U ] = U
44604460
types/Test.C#TypeType.T5#[U] => typeparam U
44614461
types/Test.C#TypeType.m2(). => method m2 [typeparam T2 = C]: Nothing
44624462
types/Test.C#TypeType.m2().[T2] => typeparam T2 = C
4463-
types/Test.C#TypeType.m3(). => method m3 [typeparam M3 [unknown local16: <?>]]: Nothing
4464-
types/Test.C#TypeType.m3().[M3] => typeparam M3 [unknown local16: <?>]
4463+
types/Test.C#TypeType.m3(). => method m3 [typeparam M3 [unknown _: <?>]]: Nothing
4464+
types/Test.C#TypeType.m3().[M3] => typeparam M3 [unknown _: <?>]
44654465
types/Test.C#`<init>`(). => primary ctor <init> (): C
44664466
types/Test.C#annType1. => val method annType1 T @ann[T]
44674467
types/Test.C#annType2. => val method annType2 T @ann1 @ann2
@@ -4482,8 +4482,8 @@ types/Test.C#superType2. => val method superType2 Int
44824482
types/Test.C#superType3. => val method superType3 Int
44834483
types/Test.C#thisType1. => val method thisType1 C.this.type
44844484
types/Test.C#thisType2. => val method thisType2 C.this.type
4485-
types/Test.C#typeLambda1(). => method typeLambda1 [typeparam M [unknown local13: <?>]]: Nothing
4486-
types/Test.C#typeLambda1().[M] => typeparam M [unknown local13: <?>]
4485+
types/Test.C#typeLambda1(). => method typeLambda1 [typeparam M [unknown _: <?>]]: Nothing
4486+
types/Test.C#typeLambda1().[M] => typeparam M [unknown _: <?>]
44874487
types/Test.C#typeRef1. => val method typeRef1 C
44884488
types/Test.C#typeRef2. => val method typeRef2 p.C
44894489
types/Test.C#typeRef3. => val method typeRef3 T#C
@@ -4680,10 +4680,10 @@ Occurrences:
46804680
[75:20..75:21): M <- types/Test.C#typeLambda1().[M]
46814681
[75:28..75:31): ??? -> scala/Predef.`???`().
46824682
[76:4..76:15): typeLambda1 -> types/Test.C#typeLambda1().
4683-
[76:24..76:25): L <- local15
4684-
[76:26..76:27): T <- local14
4683+
[76:24..76:25): L <- local11
4684+
[76:26..76:27): T <- local10
46854685
[76:31..76:35): List -> scala/package.List#
4686-
[76:36..76:37): T -> local14
4686+
[76:36..76:37): T -> local10
46874687
[78:11..78:25): ClassInfoType1 <- types/Test.C#ClassInfoType1.
46884688
[79:10..79:24): ClassInfoType2 <- types/Test.C#ClassInfoType2#
46894689
[79:33..79:34): B -> types/B#

0 commit comments

Comments
 (0)