mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
The guard added here reads the target of a member access to decide whether an assignment may move into a field initializer, and it recognises the current instance as a ThisResolveResult. Only one of the two spellings produces that. An unqualified `A` is resolved through CSharpResolver.LookInCurrentType, which synthesizes the target as a this-reference; an explicit `this.A` is built by ExpressionBuilder, whose TranslateTarget hands back whatever ConvertVariable produced - and `this` is a parameter like any other there, so the target is an ILVariableResolveResult. The guard saw the first and missed the second. Which spelling appears is decided by RequiresQualifier, for reasons unrelated to the question being asked: a constructor parameter that shadows the field forces the qualifier, and AlwaysQualifyMemberReferences forces it everywhere. So the transform hoisted `b = this.value + 1` into a field initializer, where naming the instance is CS0027 and the output does not compile. TranslateTarget already builds a ThisResolveResult for `base`, one branch above. Doing the same for `this` leaves the guard untouched and makes it see both spellings, and spares every future consumer the same trap. The type is carried over from the previous resolve result, so nothing downstream observes a different one - the this/base keyword links read exactly this node. Fixes #3984. Assisted-by: Claude:claude-opus-5:Claude Codepull/3980/head
2 changed files with 31 additions and 0 deletions
Loading…
Reference in new issue