Skip to content

Commit 199c661

Browse files
committed
New symbol creation method: newNormalizedClassSymbol.
It's common that one wants to create class symbols with arbitary parent types, not just TypeRefs. But for the casual user it's non-obvious how to do it. Hence the new creation method.
1 parent 8a3efb4 commit 199c661

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ trait Symbols { this: Context =>
109109
ClassInfo(owner.thisType, _, parents, decls, selfInfo),
110110
privateWithin, coord, assocFile)
111111

112+
/** Same as `newCompleteClassSymbol` except that `parents` can be a list of arbitary
113+
* types which get normalized into type refs and parameter bindings.
114+
*/
115+
def newNormalizedClassSymbol(
116+
owner: Symbol,
117+
name: TypeName,
118+
flags: FlagSet,
119+
parentTypes: List[Type],
120+
decls: Scope = newScope,
121+
selfInfo: Type = NoType,
122+
privateWithin: Symbol = NoSymbol,
123+
coord: Coord = NoCoord,
124+
assocFile: AbstractFile = null): ClassSymbol = {
125+
def completer = new LazyType {
126+
def complete(denot: SymDenotation)(implicit ctx: Context): Unit = {
127+
val cls = denot.asClass.classSymbol
128+
val decls = newScope
129+
val parentRefs: List[TypeRef] = normalizeToClassRefs(parentTypes, cls, decls)
130+
denot.info = ClassInfo(owner.thisType, cls, parentRefs, decls)
131+
}
132+
}
133+
newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile)
134+
}
135+
112136
/** Create a module symbol with associated module class
113137
* from its non-info fields and a function producing the info
114138
* of the module class (this info may be lazy).

0 commit comments

Comments
 (0)