@@ -151,13 +151,11 @@ object Contexts {
151151 /** The current type comparer. This ones updates itself automatically for
152152 * each new context.
153153 */
154- private [this ] var _typeComparer : TypeComparer = null
155- protected def typeComparer_= (typeComparer : TypeComparer ): Unit = {
156- assert(typeComparer.ctx eq this )
157- _typeComparer = typeComparer
158- }
159- final def typeComparer : TypeComparer = {
160- if (_typeComparer == null ) _typeComparer = outer.typeComparer.copyIn(this )
154+ private [this ] var _typeComparer : TypeComparer = _
155+ protected def typeComparer_= (typeComparer : TypeComparer ): Unit = _typeComparer = typeComparer
156+ def typeComparer : TypeComparer = {
157+ if (_typeComparer.ctx ne this )
158+ _typeComparer = _typeComparer.copyIn(this )
161159 _typeComparer
162160 }
163161
@@ -422,29 +420,31 @@ object Contexts {
422420 def useColors : Boolean =
423421 base.settings.color.value == " always"
424422
425- protected def init (outer : Context ): this .type = {
423+ protected def init (outer : Context , origin : Context ): this .type = {
424+ util.Stats .record(" Context.fresh" )
426425 _outer = outer
427- _period = outer.period
428- _mode = outer.mode
429- _owner = outer.owner
430- _tree = outer.tree
431- _scope = outer.scope
432- _typerState = outer.typerState
433- _typeAssigner = outer.typeAssigner
434- _importInfo = outer.importInfo
435- _gadt = outer.gadt
436- _searchHistory = outer.searchHistory
437- _source = outer.source
438- _moreProperties = outer.moreProperties
439- _store = outer.store
426+ _period = origin.period
427+ _mode = origin.mode
428+ _owner = origin.owner
429+ _tree = origin.tree
430+ _scope = origin.scope
431+ _typerState = origin.typerState
432+ _typeAssigner = origin.typeAssigner
433+ _importInfo = origin.importInfo
434+ _gadt = origin.gadt
435+ _searchHistory = origin.searchHistory
436+ _typeComparer = origin.typeComparer
437+ _source = origin.source
438+ _moreProperties = origin.moreProperties
439+ _store = origin.store
440440 this
441441 }
442442
443- /** A fresh clone of this context. */
444- def fresh : FreshContext = {
445- util. Stats .record( " Context.fresh " )
446- new FreshContext (base).init( this )
447- }
443+ /** A fresh clone of this context embedded in this context . */
444+ def fresh : FreshContext = freshOver( this )
445+
446+ /** A fresh clone of this context embedded in the specified `outer` context. */
447+ def freshOver ( outer : Context ) : FreshContext = new FreshContext (base).init(outer, this )
448448
449449 final def withOwner (owner : Symbol ): Context =
450450 if (owner ne this .owner) fresh.setOwner(owner) else this
0 commit comments