@@ -18,11 +18,10 @@ import io.AbstractFile
18
18
19
19
trait Symbols { this : Context =>
20
20
21
- def newLazyTermSymbol (owner : Symbol , name : TermName , initFlags : FlagSet , completer : SymCompleter ) =
22
- new TermSymbol (new LazySymDenotation (_, owner, name, initFlags, completer))
23
-
24
- def newLazyTypeSymbol (owner : Symbol , name : TypeName , initFlags : FlagSet , completer : SymCompleter ) =
25
- new TypeSymbol (new LazySymDenotation (_, owner, name, initFlags, completer))
21
+ def newLazySymbol [N <: Name ](owner : Symbol , name : N , initFlags : FlagSet , completer : SymCompleter ) =
22
+ new Symbol (new LazySymDenotation (_, owner, name, initFlags, completer)) {
23
+ type ThisName = N
24
+ }
26
25
27
26
def newLazyClassSymbol (owner : Symbol , name : TypeName , initFlags : FlagSet , completer : ClassCompleter , assocFile : AbstractFile = null ) =
28
27
new ClassSymbol (new LazyClassDenotation (_, owner, name, initFlags, completer, assocFile)(this ))
@@ -33,7 +32,7 @@ trait Symbols { this: Context =>
33
32
completer : ClassCompleter ,
34
33
assocFile : AbstractFile = null )
35
34
= {
36
- val module = newLazyTermSymbol (
35
+ val module = newLazySymbol (
37
36
owner, name, flags | ModuleCreationFlags , new ModuleCompleter (condensed))
38
37
val modcls = newLazyClassSymbol(
39
38
owner, name.toTypeName, flags | ModuleClassCreationFlags , completer, assocFile)
@@ -47,30 +46,10 @@ trait Symbols { this: Context =>
47
46
def newLazyPackageSymbols (owner : Symbol , name : TermName , completer : ClassCompleter ) =
48
47
newLazyModuleSymbols(owner, name, PackageCreationFlags , completer)
49
48
50
- def newSymbol (owner : Symbol , name : Name , flags : FlagSet , info : Type , privateWithin : Symbol = NoSymbol ): Symbol =
51
- if (name.isTermName) newTermSymbol(owner, name.asTermName, flags, info, privateWithin)
52
- else newTypeSymbol(owner, name.asTypeName, flags, info, privateWithin)
53
-
54
- def newTermSymbol (
55
- owner : Symbol ,
56
- name : TermName ,
57
- flags : FlagSet ,
58
- info : Type ,
59
- privateWithin : Symbol = NoSymbol )
60
- =
61
- new TermSymbol (new CompleteSymDenotation (_, owner, name, flags, privateWithin, info))
62
-
63
- def newTypeSymbol (
64
- owner : Symbol ,
65
- name : TypeName ,
66
- flags : FlagSet ,
67
- info : Type ,
68
- privateWithin : Symbol = NoSymbol )
69
- =
70
- new TypeSymbol (new CompleteSymDenotation (_, owner, name, flags, privateWithin, info))
71
-
72
- def newAliasTypeSymbol (owner : Symbol , name : TypeName , alias : Type , flags : FlagSet = EmptyFlags , privateWithin : Symbol = NoSymbol ) =
73
- newTypeSymbol(owner, name, flags, TypeBounds (alias, alias), privateWithin)
49
+ def newSymbol [N <: Name ](owner : Symbol , name : N , flags : FlagSet , info : Type , privateWithin : Symbol = NoSymbol ) =
50
+ new Symbol (new CompleteSymDenotation (_, owner, name, flags, privateWithin, info)) {
51
+ type ThisName = N
52
+ }
74
53
75
54
def newClassSymbol (
76
55
owner : Symbol ,
@@ -95,7 +74,7 @@ trait Symbols { this: Context =>
95
74
decls : Scope = newScope,
96
75
assocFile : AbstractFile = null )(implicit ctx : Context )
97
76
= {
98
- val module = newLazyTermSymbol (owner, name, flags | ModuleCreationFlags , new ModuleCompleter (condensed))
77
+ val module = newLazySymbol (owner, name, flags | ModuleCreationFlags , new ModuleCompleter (condensed))
99
78
val modcls = newClassSymbol(
100
79
owner, name.toTypeName, classFlags | ModuleClassCreationFlags , parents, privateWithin,
101
80
optSelfType = TermRef (owner.thisType, module),
@@ -115,7 +94,7 @@ trait Symbols { this: Context =>
115
94
def newStubSymbol (owner : Symbol , name : Name )(implicit ctx : Context ): Symbol = {
116
95
def stub [Denot <: SymDenotation ] = new StubCompleter [Denot ](ctx.condensed)
117
96
name match {
118
- case name : TermName => ctx.newLazyTermSymbol (owner, name, EmptyFlags , stub)
97
+ case name : TermName => ctx.newLazySymbol (owner, name, EmptyFlags , stub)
119
98
case name : TypeName => ctx.newLazyClassSymbol(owner, name, EmptyFlags , stub)
120
99
}
121
100
}
@@ -125,7 +104,9 @@ object Symbols {
125
104
126
105
/** A Symbol represents a Scala definition/declaration or a package.
127
106
*/
128
- abstract class Symbol (denotf : Symbol => SymDenotation ) extends DotClass {
107
+ class Symbol (denotf : Symbol => SymDenotation ) extends DotClass {
108
+
109
+ type ThisName <: Name
129
110
130
111
/** Is symbol different from NoSymbol? */
131
112
def exists = true
@@ -195,7 +176,7 @@ object Symbols {
195
176
final def owner (implicit ctx : Context ): Symbol = denot.owner
196
177
197
178
/** The current name of this symbol */
198
- final def name (implicit ctx : Context ): Name = denot.name
179
+ final def name (implicit ctx : Context ): ThisName = denot.name. asInstanceOf [ ThisName ]
199
180
200
181
/** The current type info of this symbol */
201
182
final def info (implicit ctx : Context ): Type = denot.info
@@ -393,12 +374,6 @@ object Symbols {
393
374
394
375
// def isMethod(implicit ctx: Context): Boolean = denot.isMethod
395
376
396
- }
397
-
398
- class TermSymbol (denotf : Symbol => SymDenotation ) extends Symbol (denotf)
399
-
400
- class TypeSymbol (denotf : Symbol => SymDenotation ) extends Symbol (denotf) {
401
-
402
377
/** The type representing the type constructor for this type symbol */
403
378
def typeConstructor (implicit ctx : Context ): TypeRef = denot.typeConstructor
404
379
@@ -408,7 +383,13 @@ object Symbols {
408
383
def variance (implicit ctx : Context ): Int = denot.variance
409
384
}
410
385
411
- class ClassSymbol (denotf : ClassSymbol => ClassDenotation ) extends TypeSymbol (s => denotf(s.asClass)) {
386
+ type TermSymbol = Symbol { type ThisName = TermName }
387
+ type TypeSymbol = Symbol { type ThisName = TypeName }
388
+
389
+ class ClassSymbol (denotf : ClassSymbol => ClassDenotation ) extends Symbol (s => denotf(s.asClass)) {
390
+
391
+ type ThisName = TypeName
392
+
412
393
private var superIdHint : Int = - 1
413
394
414
395
final def classDenot (implicit ctx : Context ): ClassDenotation =
@@ -448,28 +429,19 @@ object Symbols {
448
429
}
449
430
}
450
431
451
- trait ErrorSymbol {
452
- val underlying : Symbol
453
- def getMsg : String
454
- }
455
-
456
- class ErrorTypeSymbol (val underlying : Symbol , msg : => String )(implicit ctx : Context ) extends TypeSymbol (sym => underlying.denot) with ErrorSymbol {
457
- def getMsg = msg
458
- }
459
-
460
- class ErrorTermSymbol (val underlying : Symbol , msg : => String )(implicit ctx : Context ) extends TermSymbol (sym => underlying.denot) with ErrorSymbol {
461
- def getMsg = msg
432
+ class ErrorSymbol (val underlying : Symbol , msg : => String )(implicit ctx : Context ) extends Symbol (sym => underlying.denot) {
433
+ type ThisName = underlying.ThisName
462
434
}
463
435
464
436
object NoSymbol extends Symbol (sym => NoDenotation ) {
465
437
override def exists = false
466
438
}
467
439
468
- implicit class Copier (sym : Symbol )(implicit ctx : Context ) {
440
+ implicit class Copier [ N <: Name ] (sym : Symbol { type ThisName = N } )(implicit ctx : Context ) {
469
441
/** Copy a symbol, overriding selective fields */
470
442
def copy (
471
443
owner : Symbol = sym.owner,
472
- name : Name = sym.name,
444
+ name : N = sym.name,
473
445
flags : FlagSet = sym.flags,
474
446
privateWithin : Symbol = sym.privateWithin,
475
447
info : Type = sym.info): Symbol =
0 commit comments