mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
Aggressive scalar replacement propagated a display-class field to its source variable even when the field is mutated after initialization, aliasing two distinct source-level variables (Test9: thisField and this). Propagation is now cancelled when the field sees a second store or its address escapes, but only for propagation targets that cannot absorb the store: 'this' and variables that are themselves scalar-replaced display classes. Parameters continue to propagate, because their remaining uses are already restricted by ResolveVariableToPropagate and a captured parameter mutated inside a lambda (DelegateConstruction's Bug951) must keep mapping to the parameter. Checking CanPropagate first also keeps the guard away from Mono state-machine fields, whose VariableToDeclare is pre-bound to a state-machine variable that Propagate(null) would discard. Re-enables Test9 and adds Test10 covering the escaping-address variant (Interlocked.Exchange(ref displayClass.thisField, ...)). Assisted-by: OpenCode:openai/gpt-5.5:OpenCode Assisted-by: Claude:claude-fable-5:Claude Codepull/3943/head
3 changed files with 70 additions and 18 deletions
Loading…
Reference in new issue