Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

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

  • Binary operation handler: Registers OperationKind.Binary to detect DateTime/DateTimeOffset type mismatches in comparison operators
  • Direct type checking: Falls back to source/target type comparison when MethodSymbol is unavailable
  • Nullable support: Unwraps Nullable<T> types for accurate comparison

Example

Now detects conversions in lambda expressions:

// Previously undetected, now caught
list.Where(pair => {
    DateTime dt = pair.DateTime;
    DateTimeOffset dto = pair.DateTimeOffset;
    return dt < dto;  // ⚠️ INTL0202
});

Limitations

Property access in binary operations (pair.DateTime < pair.DateTimeOffset) remains undetected. Roslyn doesn't generate standard IConversionOperation nodes for property references in comparisons - requires investigation of IPropertyReferenceOperation wrapping 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
    • Triggering command: /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)
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>INTL0202 when conversion in lambda func</issue_title>
<issue_description>I would expect INTL0202 to be triggered here:

image
public override IQueryable<TimeEntry> GetQuery(IDataSourceParameters parameters)
{
    var query = Db.TimeEntries
    .Where(te =>
    te. EndDate <= EndDate.Date.AddDays(1).AddTicks(-1) &&
    te. StartDate > StartDate.Date

See also https://github.com/IntelliTect-dev/StormingTheCastle/issues/2139#issuecomment-1881630056</issue_description>

<agent_instructions>https://github.com/IntelliTect/CodingGuidelines/pull/255/changes</agent_instructions>

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


💡 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.

@BenjaminMichaelis BenjaminMichaelis force-pushed the copilot/fix-intl0202-lambda-conversion branch from 732a881 to e7bd995 Compare February 3, 2026 00:30
Copilot AI changed the title [WIP] Fix INTL0202 error in lambda function conversion INTL0202: Add binary operation detection for DateTime/DateTimeOffset conversions Feb 3, 2026
Comment on lines +55 to +58
if (dateTimeType is null || dateTimeOffsetType is null)
{
return;
}
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

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

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.

INTL0202 when conversion in lambda func

3 participants