@@ -6,6 +6,7 @@ import core.Symbols._
6
6
import core .Contexts .Context
7
7
import core .Types ._
8
8
import core .Annotations .Annotation
9
+ import core .Flags .EmptyFlags
9
10
import ast .tpd ._
10
11
11
12
import dotty .tools .dotc .{semanticdb => s }
@@ -16,11 +17,11 @@ object SymbolOps:
16
17
extension (sym : Symbol )
17
18
def sig (using LinkMode , Context ): s.Signature =
18
19
import TypeOps ._
20
+ val sig = sym.info.toSemanticSig(sym)
19
21
println(" " )
20
22
println(sym.toString)
21
23
println(s " =========sym.info================ " )
22
24
pprint.pprintln(sym.info)
23
- val sig = sym.info.toSemanticSig(sym)
24
25
println(s " =========sig================ " )
25
26
pprint.pprintln(sig)
26
27
sig
@@ -32,7 +33,9 @@ object TypeOps:
32
33
def loop (tpe : Type ): s.Signature = tpe match {
33
34
case mt : MethodType =>
34
35
val stparams = Some (s.Scope ())
35
- val sparamss = sym.rawParamss.map(_.sscope)
36
+ val paramss =
37
+ if (sym.rawParamss.nonEmpty) sym.rawParamss else sym.paramSymss
38
+ val sparamss = paramss.map(_.sscope)
36
39
s.MethodSignature (
37
40
stparams,
38
41
sparamss,
@@ -46,7 +49,7 @@ object TypeOps:
46
49
else None
47
50
val sparents = cls.parents.map(_.toSemanticType(sym))
48
51
val sself = cls.selfType.toSemanticType(sym)
49
- val decls = cls.decls.toList.sscope( using LinkMode . HardlinkChildren )
52
+ val decls = cls.decls.toList.sscope
50
53
s.ClassSignature (stparams, sparents, sself, Some (decls))
51
54
52
55
case TypeBounds (lo, hi) =>
@@ -61,11 +64,15 @@ object TypeOps:
61
64
case pt : PolyType =>
62
65
loop(pt.resType) match {
63
66
case m : s.MethodSignature =>
64
- val tparamss = sym.rawParamss.filter(ps => ps.forall(_.isTypeParam))
67
+ val paramss =
68
+ if (sym.rawParamss.nonEmpty) sym.rawParamss else sym.paramSymss
69
+ val tparamss = paramss.filter(ps => ps.forall(_.isTypeParam))
65
70
val stparams = tparamss.flatten.sscope
66
71
m.copy(typeParameters = Some (stparams))
67
72
case v : s.ValueSignature =>
68
- val tparamss = sym.rawParamss.filter(ps => ps.forall(_.isTypeParam))
73
+ val paramss =
74
+ if (sym.rawParamss.nonEmpty) sym.rawParamss else sym.paramSymss
75
+ val tparamss = paramss.filter(ps => ps.forall(_.isTypeParam))
69
76
val stparams = tparamss.flatten.sscope
70
77
s.ValueSignature (s.UniversalType (Some (stparams), v.tpe))
71
78
case _ => s.Signature .Empty
@@ -130,7 +137,6 @@ object TypeOps:
130
137
131
138
case rt @ RefinedType (parent, name, info) =>
132
139
// `X { def x: Int; def y: Int }`
133
- //
134
140
// RefinedType(
135
141
// parent = RefinedType(
136
142
// parent = TypeRef(..., X)
@@ -139,39 +145,32 @@ object TypeOps:
139
145
// refinedName = x
140
146
// refinedInfo = TypeRef(..., Int)
141
147
// )
142
-
143
148
type RefinedInfo = (core.Names .Name , Type )
144
149
def flatten (tpe : Type , acc : List [RefinedInfo ]): (Type , List [RefinedInfo ]) = tpe match {
145
150
case RefinedType (parent, name, info) =>
146
151
flatten(parent, acc :+ (name, info))
147
152
case _ =>
148
153
(tpe, acc)
149
154
}
150
- val (parent, refinedInfos) = flatten(rt, List .empty)
151
155
152
- val stpe = parent match {
153
- // val tp: M with N { def k: Int } = ???
154
- case AndType (x, y) =>
155
- s.WithType (Seq (loop(x), loop(y))) // TODO: for M with N with L
156
- case _ =>
157
- s.WithType (Seq (loop(parent)))
156
+ // flatten parent types to list
157
+ // e.g. `X with Y with Z { refined }`
158
+ // RefinedType(parent = AndType(X, AndType(Y, Z)), ...)
159
+ // => List(X, Y, Z)
160
+ def flattenParent (parent : Type ): List [s.Type ] = parent match {
161
+ case AndType (tp1, tp2) =>
162
+ flattenParent(tp1) ++ flattenParent(tp2)
163
+ case _ => List (loop(parent))
158
164
}
159
- val decls = for {
165
+
166
+ val (parent, refinedInfos) = flatten(rt, List .empty)
167
+ val stpe = s.WithType (flattenParent(parent))
168
+
169
+ // Create dummy symbols for refinements
170
+ // since there's no way to retrieve symbols of refinements from RefinedType at this moment.
171
+ val decls = for
160
172
(name, info) <- refinedInfos
161
- } yield {
162
- // do we need this?
163
- // isLegalPrefix returns true outside in typer
164
- val pre = ctx.typeAssigner.maybeSkolemizePrefix(rt, name)
165
- val denot = rt.findMember(name, pre)
166
- // assert(denot.info eq info, s"(${denot.info.show}) is not eq to (${info.show})")
167
- println(s " denot.info: ${denot.info}, info: ${info}, sym: ${denot.symbol}" )
168
- val sym =
169
- if denot.symbol.exists then
170
- println(s " refined ${denot.symbol.show} with ${info.show}" )
171
- denot.symbol
172
- else ???
173
- sym
174
- }
173
+ yield newSymbol(sym, name, EmptyFlags , info)
175
174
val sdecls = decls.sscope(using LinkMode .HardlinkChildren )
176
175
s.StructuralType (stpe, Some (sdecls))
177
176
0 commit comments