@@ -662,6 +662,14 @@ object SymDenotations {
662
662
if (cls.effectiveName == name || ! cls.exists) cls else cls.owner.enclosingClassNamed(name)
663
663
}
664
664
665
+ /** The closest enclosing method containing this definition.
666
+ * A local dummy owner is mapped to the primary constructor of the class.
667
+ */
668
+ final def enclosingMethod (implicit ctx : Context ): Symbol =
669
+ if (this is Method ) symbol
670
+ else if (this .isClass) primaryConstructor
671
+ else owner.enclosingMethod
672
+
665
673
/** The top-level class containing this denotation,
666
674
* except for a toplevel module, where its module class is returned.
667
675
*/
@@ -901,7 +909,7 @@ object SymDenotations {
901
909
privateWithin : Symbol = null ,
902
910
annotations : List [Annotation ] = null )(implicit ctx : Context ) =
903
911
{ // simulate default parameters, while also passing implicit context ctx to the default values
904
- val initFlags1 = if (initFlags != UndefinedFlags ) initFlags else this .flags
912
+ val initFlags1 = if (initFlags != UndefinedFlags ) initFlags else this .flags &~ Frozen
905
913
val info1 = if (info != null ) info else this .info
906
914
val privateWithin1 = if (privateWithin != null ) privateWithin else this .privateWithin
907
915
val annotations1 = if (annotations != null ) annotations else this .annotations
@@ -1172,23 +1180,28 @@ object SymDenotations {
1172
1180
/** Enter a symbol in current scope.
1173
1181
* Note: We require that this does not happen after the first time
1174
1182
* someone does a findMember on a subclass.
1183
+ * @param scope The scope in which symbol should be entered.
1184
+ * If this is EmptyScope, the scope is `decls`.
1185
+ * @param replace Replace any existing symbol with same name.
1186
+ * This is always done if this denotes a package class.
1175
1187
*/
1176
- def enter (sym : Symbol , scope : Scope = EmptyScope )(implicit ctx : Context ): Unit = {
1188
+ def enter (sym : Symbol , scope : Scope = EmptyScope , replace : Boolean = false )(implicit ctx : Context ): Unit = {
1177
1189
val mscope = scope match {
1178
1190
case scope : MutableScope => scope
1179
1191
case _ => decls.asInstanceOf [MutableScope ]
1180
1192
}
1181
- if (this is PackageClass ) { // replace existing symbols
1193
+ if (replace || ( this is PackageClass )) {
1182
1194
val entry = mscope.lookupEntry(sym.name)
1183
1195
if (entry != null ) {
1196
+ if (entry.sym == sym) return
1184
1197
mscope.unlink(entry)
1185
1198
entry.sym.denot = sym.denot // to avoid stale symbols
1186
1199
}
1187
1200
}
1188
1201
enterNoReplace(sym, mscope)
1189
1202
}
1190
1203
1191
- /** Enter a symbol in current scope without potentially replacing the old copy. */
1204
+ /** Enter a symbol in given ` scope` without potentially replacing the old copy. */
1192
1205
def enterNoReplace (sym : Symbol , scope : MutableScope )(implicit ctx : Context ): Unit = {
1193
1206
require(! (this is Frozen ))
1194
1207
scope.enter(sym)
0 commit comments