Skip to content

Remove unsafe generic-body convenience properties from OperationSyntax#16

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/remove-unsafe-generic-body-properties
Closed

Remove unsafe generic-body convenience properties from OperationSyntax#16
Copilot wants to merge 2 commits intomainfrom
copilot/remove-unsafe-generic-body-properties

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

OperationSyntax exposed properties (GenericBody, OperandList, SuccessorList, Regions, Attributes, TypeSignatureColonToken, TypeSignatureSyntax, and several derivatives) that implicitly called Body.GetGenericBody(), which throws for custom assembly bodies. This hid the generic/custom body distinction and caused runtime exceptions in otherwise reasonable-looking code.

Changes

  • OperationSyntax — Removed all 11 properties that delegated through GetGenericBody(), including the explicit 7 from the issue scope plus audited derivatives: TryGetRawTypeSignature, RawTypeSignature, Operands, Successors. TryGetGenericBody is retained as the safe, explicit accessor.

  • Binder, GenericSyntaxBuilder, AssemblySyntaxBuilder — Updated to branch on TryGetGenericBody. Binder falls back to empty collections when no generic projection is available; AssemblySyntaxBuilder.BuildGenericBody throws InvalidOperationException (programming error); GenericSyntaxBuilder skips operations without a generic projection.

  • Operation.TypeSignature — Updated to use TryGetGenericBody instead of Syntax.RawTypeSignature.

  • Tests — Updated all call sites to explicitly pattern-match on Body:

// Before
var operands = operation.OperandList;

// After — direct cast for known-generic ops
var body = (GenericOperationBodySyntax)operation.Body;
var operands = body.OperandList;

// After — TryGetGenericBody for custom bodies that expose a generic projection
if (operation.TryGetGenericBody(out var body))
{
    var operands = body!.OperandList;
}

⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] Remove unsafe generic-body convenience properties from OperationSyntax Remove unsafe generic-body convenience properties from OperationSyntax Mar 29, 2026
Copilot AI requested a review from jonathanvdc March 29, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unsafe generic-body convenience properties from OperationSyntax

2 participants