Skip to content

Commit dd7c68b

Browse files
committed
Fix substituters
There's something problematic going on here. TypeMaps usually take a context as a parameter, which becomes a private parameter acessor field. That parameter shadows the mapCtx field inherited from TypeMap. `mapCtx` is a variable that is temporarily mutated when mapping LazyRefs. But since it is shadowed, such mutations do not affect code that is defined in the subclass of TypeMap. One fix is to explicitly pass mapCtx to all code that is called from the maps. That's what's done here for substituters. There might be other solutions as well, which have to be tried out.
1 parent 804ac94 commit dd7c68b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

compiler/src/dotty/tools/dotc/core/Substituters.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,39 +162,39 @@ object Substituters:
162162
}
163163

164164
final class SubstBindingMap(from: BindingType, to: BindingType)(using Context) extends DeepTypeMap {
165-
def apply(tp: Type): Type = subst(tp, from, to, this)
165+
def apply(tp: Type): Type = subst(tp, from, to, this)(using mapCtx)
166166
}
167167

168168
final class Subst1Map(from: Symbol, to: Type)(using Context) extends DeepTypeMap {
169-
def apply(tp: Type): Type = subst1(tp, from, to, this)
169+
def apply(tp: Type): Type = subst1(tp, from, to, this)(using mapCtx)
170170
}
171171

172172
final class Subst2Map(from1: Symbol, to1: Type, from2: Symbol, to2: Type)(using Context) extends DeepTypeMap {
173-
def apply(tp: Type): Type = subst2(tp, from1, to1, from2, to2, this)
173+
def apply(tp: Type): Type = subst2(tp, from1, to1, from2, to2, this)(using mapCtx)
174174
}
175175

176176
final class SubstMap(from: List[Symbol], to: List[Type])(using Context) extends DeepTypeMap {
177-
def apply(tp: Type): Type = subst(tp, from, to, this)
177+
def apply(tp: Type): Type = subst(tp, from, to, this)(using mapCtx)
178178
}
179179

180180
final class SubstSymMap(from: List[Symbol], to: List[Symbol])(using Context) extends DeepTypeMap {
181-
def apply(tp: Type): Type = substSym(tp, from, to, this)
181+
def apply(tp: Type): Type = substSym(tp, from, to, this)(using mapCtx)
182182
}
183183

184184
final class SubstThisMap(from: ClassSymbol, to: Type)(using Context) extends DeepTypeMap {
185-
def apply(tp: Type): Type = substThis(tp, from, to, this)
185+
def apply(tp: Type): Type = substThis(tp, from, to, this)(using mapCtx)
186186
}
187187

188188
final class SubstRecThisMap(from: Type, to: Type)(using Context) extends DeepTypeMap {
189-
def apply(tp: Type): Type = substRecThis(tp, from, to, this)
189+
def apply(tp: Type): Type = substRecThis(tp, from, to, this)(using mapCtx)
190190
}
191191

192192
final class SubstParamMap(from: ParamRef, to: Type)(using Context) extends DeepTypeMap {
193-
def apply(tp: Type): Type = substParam(tp, from, to, this)
193+
def apply(tp: Type): Type = substParam(tp, from, to, this)(using mapCtx)
194194
}
195195

196196
final class SubstParamsMap(from: BindingType, to: List[Type])(using Context) extends DeepTypeMap {
197-
def apply(tp: Type): Type = substParams(tp, from, to, this)
197+
def apply(tp: Type): Type = substParams(tp, from, to, this)(using mapCtx)
198198
}
199199

200200
/** An approximating substitution that can handle wildcards in the `to` list */

0 commit comments

Comments
 (0)