Conversation
siegfriedpammer
added a commit
that referenced
this pull request
Aug 29, 2026
NullPropagationTransform only rewrites "x != null ? x.Chain : fallback" into "x?.Chain ?? fallback" when the chain's inferred type is a non-nullable value type, and InferType had no case for ldlen. Array length therefore came back as UnknownType, so "arr?.Length ?? 0" was left as a ternary. The inferred type mirrors ExpressionBuilder.VisitLdLen, which decides between Array.Length and Array.LongLength from the result type alone. Found while investigating #3704, where the surviving ternary also keeps the tested array in a stack slot and strands the typeof of a dynamic call's static target. That issue is fixed separately in #4072. Assisted-by: Claude:claude-opus-5[1m]:Claude Code
siegfriedpammer
force-pushed
the
fix/3704-static-type-target
branch
from
August 29, 2026 18:09
af75e7c to
1c9d2f2
Compare
dgrunwald
approved these changes
Aug 29, 2026
siegfriedpammer
force-pushed
the
fix/3704-static-type-target
branch
from
August 29, 2026 20:38
1c9d2f2 to
adddb04
Compare
A dynamic call site that names a type passes typeof(T) as its target. When a later argument contains control flow, the compiler stores that typeof in a temporary. ILInlining does not undo this: it inlines a store only into the immediately following instruction, so an intervening statement leaves the typeof behind, and the expression builder printed the temporary instead of the type. Substituting the typeof back into the target slot is not an option either, because a call there has side effects and blocks inlining of the remaining arguments. The type is therefore stored on the instruction. Object creation already did this, but kept the field private, so the expression builder re-derived the type from the target argument and failed on the spilled form. Member invocation gets the same field. Both drop the target from Arguments, so the dead-argument handling removes the store; ArgumentInfo keeps its entry for the target, because the invocation symbol is built from it. The type of an object creation is not nullable: the transform returns before constructing the instruction when it cannot match the typeof, and substitutes the unknown type otherwise. An unresolvable type therefore reaches the expression builder as the unresolved type it is, and prints as `?` like any other, rather than being indistinguishable from a missing one. Those two are also the only binder method kinds that ever see CSharpArgumentInfoFlags.IsStaticType. Every other way of naming a type as the receiver binds statically and leaves only a conversion of the dynamic operand behind. Assisted-by: Claude:claude-opus-5[1m]:Claude Code
siegfriedpammer
force-pushed
the
fix/3704-static-type-target
branch
from
August 29, 2026 20:41
adddb04 to
8ab3f93
Compare
dgrunwald
approved these changes
Aug 29, 2026
| { | ||
| Expression targetExpr; | ||
| var target = TranslateDynamicTarget(inst.Arguments[0], inst.ArgumentInfo[0]); | ||
| var target = inst.StaticTargetType is IType staticTargetType |
Member
There was a problem hiding this comment.
This is another weird null check.
Reviewed with Stampeded!
siegfriedpammer
added a commit
that referenced
this pull request
Aug 29, 2026
NullPropagationTransform only rewrites "x != null ? x.Chain : fallback" into "x?.Chain ?? fallback" when the chain's inferred type is a non-nullable value type, and InferType had no case for ldlen. Array length therefore came back as UnknownType, so "arr?.Length ?? 0" was left as a ternary. The inferred type mirrors ExpressionBuilder.VisitLdLen, which decides between Array.Length and Array.LongLength from the result type alone. Found while investigating #3704, where the surviving ternary also keeps the tested array in a stack slot and strands the typeof of a dynamic call's static target. That issue is fixed separately in #4072, whose DynamicTests cases pinned the ternary as expected output; those blocks round-trip exactly now, so they are gone. Also carries a review follow-up that missed #4072: the static-target test in VisitDynamicInvokeMemberInstruction is a plain null check, the way DynamicInvokeMemberInstruction itself tests the field, rather than a pattern match binding a name it does not need. Assisted-by: Claude:claude-opus-5[1m]:Claude Code
siegfriedpammer
added a commit
that referenced
this pull request
Aug 30, 2026
NullPropagationTransform only rewrites "x != null ? x.Chain : fallback" into "x?.Chain ?? fallback" when the chain's inferred type is a non-nullable value type, and InferType had no case for ldlen. Array length therefore came back as UnknownType, so "arr?.Length ?? 0" was left as a ternary. The inferred type mirrors ExpressionBuilder.VisitLdLen, which decides between Array.Length and Array.LongLength from the result type alone. Found while investigating #3704, where the surviving ternary also keeps the tested array in a stack slot and strands the typeof of a dynamic call's static target. That issue is fixed separately in #4072, whose DynamicTests cases pinned the ternary as expected output; those blocks round-trip exactly now, so they are gone. Also carries a review follow-up that missed #4072: the static-target test in VisitDynamicInvokeMemberInstruction is a plain null check, the way DynamicInvokeMemberInstruction itself tests the field, rather than a pattern match binding a name it does not need. Assisted-by: Claude:claude-opus-5[1m]:Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3704.
A dynamic call site that names a type passes
typeof(T)as its target. When a later argument contains control flow, the compiler stores thattypeofin a temporary, andILInliningdoes not undo it: it inlines a store only into the immediately following instruction, so an intervening statement leaves thetypeofbehind.ExpressionBuilderthen printed the temporary instead of the type, producing output that does not compile:Substituting the
typeofback into the target slot is not an option: a call there has side effects, so the inliner can no longer move the remaining arguments across it and results of dynamic operations stop collapsing into their consumer (18DynamicTestsconfigurations regress that way).The type is stored on the instruction instead.
DynamicInvokeConstructorInstructionalready resolved it that way but kept the field private, soExpressionBuilderre-derived it from the target argument and degraded to an error expression on the spilled form.DynamicInvokeMemberInstructiongets the same field. Both drop the target fromArguments, which lets the existing dead-argument bookkeeping retire the store;ArgumentInfokeeps its entry for the target, because the invocation symbol is built from it.Those two are the only binder method kinds that ever see
CSharpArgumentInfoFlags.IsStaticType- every other way of naming a type as the receiver binds statically and leaves only a conversion of the dynamic operand behind.Tests:
DynamicTestscovers a discarded result, a used result, explicit type arguments and a dynamic object creation, each with thetypeofstranded behind a surviving temporary;DynamicAwaitcovers the state-machine spill across an await.Full
ICSharpCode.Decompiler.Testsrun: 3460 passed, 0 failed, 45 skipped.🤖 Generated with Claude Code