Skip to content

Commit 12c240d

Browse files
authored
Merge pull request scala#5844 from adriaanm/rework-5816
Revert some of ade53a1. Use completer factory methods.
2 parents 15e2759 + 2804c63 commit 12c240d

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,26 @@ trait MethodSynthesis {
146146
// if there's no field symbol, the ValDef tree receives the getter symbol and thus is not a synthetic
147147
if (fieldSym != NoSymbol) {
148148
context.unit.synthetics(getterSym) = getter.derivedTree(getterSym)
149-
getterSym setInfo new namer.AccessorTypeCompleter(tree, tree.tpt.isEmpty, isBean = false, isSetter = false)
150-
} else getterSym setInfo new namer.ValTypeCompleter(tree)
149+
getterSym setInfo namer.accessorTypeCompleter(tree, tree.tpt.isEmpty, isBean = false, isSetter = false)
150+
} else getterSym setInfo namer.valTypeCompleter(tree)
151151

152152
enterInScope(getterSym)
153153

154154
if (getter.needsSetter) {
155155
val setter = Setter(tree)
156156
val setterSym = setter.createSym
157157
context.unit.synthetics(setterSym) = setter.derivedTree(setterSym)
158-
setterSym setInfo new namer.AccessorTypeCompleter(tree, tree.tpt.isEmpty, isBean = false, isSetter = true)
158+
setterSym setInfo namer.accessorTypeCompleter(tree, tree.tpt.isEmpty, isBean = false, isSetter = true)
159159
enterInScope(setterSym)
160160
}
161161

162162
// TODO: delay emitting the field to the fields phase (except for private[this] vals, which only get a field and no accessors)
163163
if (fieldSym != NoSymbol) {
164-
fieldSym setInfo new namer.ValTypeCompleter(tree)
164+
fieldSym setInfo namer.valTypeCompleter(tree)
165165
enterInScope(fieldSym)
166166
}
167167
} else {
168-
getterSym setInfo new namer.ValTypeCompleter(tree)
168+
getterSym setInfo namer.valTypeCompleter(tree)
169169
enterInScope(getterSym)
170170
}
171171

@@ -208,11 +208,11 @@ trait MethodSynthesis {
208208
sym
209209
}
210210

211-
val getterCompleter = new namer.AccessorTypeCompleter(tree, missingTpt, isBean = true, isSetter = false)
211+
val getterCompleter = namer.accessorTypeCompleter(tree, missingTpt, isBean = true, isSetter = false)
212212
enterInScope(deriveBeanAccessor(if (hasBeanProperty) "get" else "is") setInfo getterCompleter)
213213

214214
if (tree.mods.isMutable) {
215-
val setterCompleter = new namer.AccessorTypeCompleter(tree, missingTpt, isBean = true, isSetter = true)
215+
val setterCompleter = namer.accessorTypeCompleter(tree, missingTpt, isBean = true, isSetter = true)
216216
enterInScope(deriveBeanAccessor("set") setInfo setterCompleter)
217217
}
218218
}

src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ trait Namers extends MethodSynthesis {
105105

106106
def enterValueParams(vparamss: List[List[ValDef]]): List[List[Symbol]] =
107107
mmap(vparamss) { param =>
108-
enterInScope(assignMemberSymbol(param, mask = ValueParameterFlags)) setInfo new MonoTypeCompleter(param)
108+
enterInScope(assignMemberSymbol(param, mask = ValueParameterFlags)) setInfo monoTypeCompleter(param)
109109
}
110110

111111
protected def owner = context.owner
@@ -337,10 +337,8 @@ trait Namers extends MethodSynthesis {
337337
}
338338
}
339339

340-
def createImportSymbol(tree: Import) = {
341-
val importNamer = namerOf(tree.symbol)
342-
NoSymbol.newImport(tree.pos) setInfo new importNamer.ImportTypeCompleter(tree)
343-
}
340+
def createImportSymbol(tree: Import) =
341+
NoSymbol.newImport(tree.pos) setInfo (namerOf(tree.symbol) importTypeCompleter tree)
344342

345343
/** All PackageClassInfoTypes come from here. */
346344
def createPackageSymbol(pos: Position, pid: RefTree): Symbol = {
@@ -430,8 +428,7 @@ trait Namers extends MethodSynthesis {
430428

431429
def enterModuleDef(tree: ModuleDef) = {
432430
val sym = enterModuleSymbol(tree)
433-
val mcsNamer = namerOf(sym)
434-
sym.moduleClass setInfo new mcsNamer.ModuleClassTypeCompleter(tree)
431+
sym.moduleClass setInfo namerOf(sym).moduleClassTypeCompleter(tree)
435432
sym setInfo completerOf(tree)
436433
validateCompanionDefs(tree)
437434
sym
@@ -684,8 +681,7 @@ trait Namers extends MethodSynthesis {
684681
}
685682

686683
def completerOf(tree: MemberDef): TypeCompleter = {
687-
val treeNamer = namerOf(tree.symbol)
688-
val mono = new treeNamer.MonoTypeCompleter(tree)
684+
val mono = namerOf(tree.symbol) monoTypeCompleter tree
689685
val tparams = treeInfo.typeParameters(tree)
690686
if (tparams.isEmpty) mono
691687
else {
@@ -1081,7 +1077,7 @@ trait Namers extends MethodSynthesis {
10811077

10821078
val sym = (
10831079
if (hasType || hasName) {
1084-
owner.typeOfThis = if (hasType) new SelfTypeCompleter(tpt) else owner.tpe_*
1080+
owner.typeOfThis = if (hasType) selfTypeCompleter(tpt) else owner.tpe_*
10851081
val selfSym = owner.thisSym setPos self.pos
10861082
if (hasName) selfSym setName name else selfSym
10871083
}
@@ -1175,7 +1171,7 @@ trait Namers extends MethodSynthesis {
11751171
val res = GenPolyType(tparams0, resultType)
11761172
val pluginsTp = pluginsTypeSig(res, typer, cdef, WildcardType)
11771173

1178-
// Already assign the type to the class symbol (MonoTypeCompleter will do it again).
1174+
// Already assign the type to the class symbol (monoTypeCompleter will do it again).
11791175
// Allows isDerivedValueClass to look at the info.
11801176
clazz setInfo pluginsTp
11811177
if (clazz.isDerivedValueClass) {
@@ -1189,7 +1185,7 @@ trait Namers extends MethodSynthesis {
11891185

11901186
private def moduleSig(mdef: ModuleDef): Type = {
11911187
val moduleSym = mdef.symbol
1192-
// The info of both the module and the moduleClass symbols need to be assigned. MonoTypeCompleter assigns
1188+
// The info of both the module and the moduleClass symbols need to be assigned. monoTypeCompleter assigns
11931189
// the result of typeSig to the module symbol. The module class info is assigned here as a side-effect.
11941190
val result = templateSig(mdef.impl)
11951191
val pluginsTp = pluginsTypeSig(result, typer, mdef, WildcardType)
@@ -1589,7 +1585,7 @@ trait Namers extends MethodSynthesis {
15891585
// (a val's name ends in a " ", so can't compare to def)
15901586
val overridingSym = if (isGetter) vdef.symbol else vdef.symbol.getterIn(valOwner)
15911587

1592-
// We're called from an AccessorTypeCompleter, which is completing the info for the accessor's symbol,
1588+
// We're called from an accessorTypeCompleter, which is completing the info for the accessor's symbol,
15931589
// which may or may not be `vdef.symbol` (see isGetter above)
15941590
val overridden = safeNextOverriddenSymbol(overridingSym)
15951591

@@ -1732,7 +1728,7 @@ trait Namers extends MethodSynthesis {
17321728
}
17331729

17341730
/**
1735-
* TypeSig is invoked by MonoTypeCompleters. It returns the type of a definition which
1731+
* TypeSig is invoked by monoTypeCompleters. It returns the type of a definition which
17361732
* is then assigned to the corresponding symbol (typeSig itself does not need to assign
17371733
* the type to the symbol, but it can if necessary).
17381734
*/
@@ -1923,6 +1919,11 @@ trait Namers extends MethodSynthesis {
19231919
}
19241920
}
19251921

1922+
@deprecated("Instantiate TypeCompleterBase (for monomorphic, non-wrapping completer) or CompleterWrapper directly.", "2.12.2")
1923+
def mkTypeCompleter(t: Tree)(c: Symbol => Unit) = new TypeCompleterBase(t) {
1924+
def completeImpl(sym: Symbol) = c(sym)
1925+
}
1926+
19261927
// NOTE: only meant for monomorphic definitions,
19271928
// do not use to wrap existing completers (see CompleterWrapper for that)
19281929
abstract class TypeCompleterBase[T <: Tree](val tree: T) extends LockingTypeCompleter with FlagAgnosticCompleter

0 commit comments

Comments
 (0)