@@ -133,12 +133,65 @@ static void Main(string[] args)
133133
134134 }
135135
136+ [ TestMethod ]
137+ public void UsageOfImplicitConversion_InLinqWithVariables_ProducesWarningMessage ( )
138+ {
139+ string source = @"
140+ using System;
141+ using System.Collections.Generic;
142+ using System.Linq;
143+
144+ namespace ConsoleApp1
145+ {
146+ internal class Pair(DateTimeOffset DateTimeOffset, DateTime DateTime);
147+
148+ internal class Program
149+ {
150+ static void Main(string[] args)
151+ {
152+ List<Pair> list = new(){ new(DateTimeOffset.Now, DateTime.Now) };
153+ _ = list.Where(pair => {
154+ DateTimeOffset first = pair.DateTimeOffset;
155+ DateTime second = pair.DateTime;
156+ return first < second;
157+ });
158+ }
159+ }
160+ }" ;
161+
162+ VerifyCSharpDiagnostic (
163+ source ,
164+ new DiagnosticResult
165+ {
166+ Id = "INTL0202" ,
167+ Severity = DiagnosticSeverity . Warning ,
168+ Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior" ,
169+ Locations = [ new DiagnosticResultLocation ( "Test0.cs" , 18 , 32 ) ]
170+ }
171+ ) ;
172+ }
173+
136174 [ TestMethod ]
137175 public void UsageOfImplicitConversion_InLinq_ProducesWarningMessage ( )
138176 {
139- string dir = Directory . GetParent ( Environment . CurrentDirectory ) . Parent . Parent . FullName ;
140- string path = Path . Combine ( dir , "Data" , "DateTime_ImplicitConversion_InLinq.cs" ) ;
141- string source = File . ReadAllText ( path ) ;
177+ string source = @"
178+ using System;
179+ using System.Collections.Generic;
180+ using System.Linq;
181+
182+ namespace ConsoleApp1
183+ {
184+ internal class Pair(DateTimeOffset DateTimeOffset, DateTime DateTime);
185+
186+ internal class Program
187+ {
188+ static void Main(string[] args)
189+ {
190+ List<Pair> list = new(){ new(DateTimeOffset.Now, DateTime.Now) };
191+ _ = list.Where(pair => pair.DateTimeOffset < pair.DateTime);
192+ }
193+ }
194+ }" ;
142195
143196 VerifyCSharpDiagnostic (
144197 source ,
@@ -147,7 +200,7 @@ public void UsageOfImplicitConversion_InLinq_ProducesWarningMessage()
147200 Id = "INTL0202" ,
148201 Severity = DiagnosticSeverity . Warning ,
149202 Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior" ,
150- Locations = [ new DiagnosticResultLocation ( "Test0.cs" , 17 , 25 ) ]
203+ Locations = [ new DiagnosticResultLocation ( "Test0.cs" , 15 , 36 ) ]
151204 }
152205 ) ;
153206 }
0 commit comments