-
Notifications
You must be signed in to change notification settings - Fork 16
INTL0202: Add binary operation detection for DateTime/DateTimeOffset conversions #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…all contexts Co-authored-by: BenjaminMichaelis <[email protected]>
732a881 to
e7bd995
Compare
…n detection (WIP) Co-authored-by: BenjaminMichaelis <[email protected]>
Co-authored-by: BenjaminMichaelis <[email protected]>
| if (dateTimeType is null || dateTimeOffsetType is null) | ||
| { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably just throw if these types are not found.
|
|
||
| private void CheckBinaryOperandPair(OperationAnalysisContext context, IOperation operand, IOperation otherOperand, INamedTypeSymbol dateTimeType, INamedTypeSymbol dateTimeOffsetType) | ||
| { | ||
| if (operand is null || operand.Type is null || otherOperand is null || otherOperand.Type is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (operand is null || operand.Type is null || otherOperand is null || otherOperand.Type is null) | |
| if (operand?.Type is null || otherOperand?.Type is null) |
| INamedTypeSymbol dateTimeType = context.Compilation.GetTypeByMetadataName("System.DateTime"); | ||
| INamedTypeSymbol dateTimeOffsetType = context.Compilation.GetTypeByMetadataName("System.DateTimeOffset"); | ||
|
|
||
| if (dateTimeType is null || dateTimeOffsetType is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again could probably just throw if these types are not resolved
INTL0202 wasn't detecting implicit DateTime→DateTimeOffset conversions in lambda expressions and LINQ queries. The analyzer only caught conversions with explicit method symbols, missing type-based conversions in comparisons.
Changes
OperationKind.Binaryto detect DateTime/DateTimeOffset type mismatches in comparison operatorsMethodSymbolis unavailableNullable<T>types for accurate comparisonExample
Now detects conversions in lambda expressions:
Limitations
Property access in binary operations (
pair.DateTime < pair.DateTimeOffset) remains undetected. Roslyn doesn't generate standardIConversionOperationnodes for property references in comparisons - requires investigation ofIPropertyReferenceOperationwrapping behavior.Test Results
76/80 analyzer tests passing. All variable-based conversion scenarios working. Property-based scenarios need additional work.
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:
pe3vsblobprodcus354.vsblob.vsassets.io/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/CodingGuidelines/CodingGuidelines/Tools/XMLtoMD/GuidelineXmlToMD.sln --packages /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true --no�� s --report /etc/cron.hourly(dns block)/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/CodingGuidelines/CodingGuidelines/Tools/XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.csproj --packages /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true show�� pr-255:IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/BanIm/low:false(dns block)/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/CodingGuidelines/CodingGuidelines/Tools/XMLtoMD/GuidelineXmlToMD.Test/GuidelineXmlToMD.Test.csproj --packages /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true -n 34,60p(dns block)s8mvsblobprodcus38.vsblob.vsassets.io/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/152969D1C94CACFB2DD8DDFC3D3B91A8/missingpackages_workingdir --packages /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force --no�� --noprofile(dns block)/home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/152969D1C94CACFB2DD8DDFC3D3B91A8/missingpackages_workingdir --packages /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/CodingGuidelines/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force /usr��(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 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.