Skip to content

Conversation

Copy link

Copilot AI commented Nov 22, 2025

The analyzer only caught explicit casts to [Closed] enums, missing implicit conversions like Rgb rgb = 0.

Changes

  • EnumClosedConversionAnalyzer: Migrated from RegisterSyntaxNodeAction(SyntaxKind.CastExpression) to RegisterOperationAction(OperationKind.Conversion) using IConversionOperation
  • ClosedTests: Updated test to verify implicit conversions now trigger errors

Example

[StaticCs.Closed]
enum Rgb { Red, Green, Blue }

class C
{
    void M()
    {
        Rgb rgb1 = (Rgb)10;  // Previously: Error ✓
        Rgb rgb2 = 0;        // Previously: No error ✗  Now: Error ✓
    }
}

The IOperation API provides semantic analysis that captures both explicit and implicit conversions, eliminating the loophole.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • ytvvsblobprodcus310.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/StaticCs/StaticCs/static-cs.sln --packages /home/REDACTED/work/StaticCs/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/StaticCs/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/StaticCs/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/StaticCs/StaticCs/test/AotTest/AotTest.csproj --packages /home/REDACTED/work/StaticCs/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/StaticCs/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/StaticCs/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Consider using IOperation</issue_title>
<issue_description>By only looking for CastExpressionSyntaxes, you're missing the implicit 0 conversion case. Consider using IOperation to avoid missing this case and not having to deal with syntax.</issue_description>

Comments on the Issue (you are @copilot in this section)

@agocke https://github.com/agocke/static-cs/blob/d9ba7fcdfcb51850a8665e1442d8cf1bafb2a655/test/Program.cs#L20-L22

Haven't gotten around to fixing it yet :)</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…onversions

Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Copilot AI changed the title [WIP] Consider using IOperation for implicit conversion Use IOperation to detect implicit integer-to-enum conversions Nov 22, 2025
Copilot AI requested a review from agocke November 22, 2025 04:30
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.

Consider using IOperation

2 participants