@@ -160,22 +160,25 @@ private static ApiData ReadApiData(string path, SourceText sourceText, bool isSh
160
160
{
161
161
var apiBuilder = ArrayBuilder < ApiLine > . GetInstance ( ) ;
162
162
var removedBuilder = ArrayBuilder < RemovedApiLine > . GetInstance ( ) ;
163
- var maxNullableRank = - 1 ;
164
- var rank = - 1 ;
163
+ var lastNullableLineNumber = - 1 ;
164
+
165
+ // current line we're on. Note: we ignore whitespace lines when computin gthis.
166
+ var lineNumber = - 1 ;
165
167
166
168
var additionalFileInfo = new AdditionalFileInfo ( path , sourceText , isShippedApi ) ;
167
169
168
170
foreach ( var line in sourceText . Lines )
169
171
{
172
+ // Skip whitespace.
170
173
var text = line . ToString ( ) ;
171
174
if ( string . IsNullOrWhiteSpace ( text ) )
172
175
continue ;
173
176
174
- rank ++ ;
177
+ lineNumber ++ ;
175
178
176
179
if ( text == NullableEnable )
177
180
{
178
- maxNullableRank = rank ;
181
+ lastNullableLineNumber = lineNumber ;
179
182
continue ;
180
183
}
181
184
@@ -191,7 +194,7 @@ private static ApiData ReadApiData(string path, SourceText sourceText, bool isSh
191
194
}
192
195
}
193
196
194
- return new ApiData ( apiBuilder . ToImmutableAndFree ( ) , removedBuilder . ToImmutableAndFree ( ) , maxNullableRank ) ;
197
+ return new ApiData ( apiBuilder . ToImmutableAndFree ( ) , removedBuilder . ToImmutableAndFree ( ) , lastNullableLineNumber ) ;
195
198
}
196
199
197
200
private static bool TryGetApiData ( AnalyzerOptions analyzerOptions , Compilation compilation , bool isPublic , List < Diagnostic > errors , CancellationToken cancellationToken , [ NotNullWhen ( true ) ] out ApiData ? shippedData , [ NotNullWhen ( true ) ] out ApiData ? unshippedData )
@@ -263,7 +266,7 @@ static ApiData Flatten(ArrayBuilder<ApiData> allData)
263
266
return new ApiData (
264
267
apiBuilder . ToImmutableAndFree ( ) ,
265
268
removedBuilder . ToImmutableAndFree ( ) ,
266
- allData . Max ( static d => d . NullableRank ) ) ;
269
+ allData . Max ( static d => d . NullableLineNumber ) ) ;
267
270
}
268
271
}
269
272
@@ -379,13 +382,13 @@ private static bool ValidateApiFiles(ApiData shippedData, ApiData unshippedData,
379
382
errors . Add ( Diagnostic . Create ( descriptor , Location . None , InvalidReasonShippedCantHaveRemoved ) ) ;
380
383
}
381
384
382
- if ( shippedData . NullableRank > 0 )
385
+ if ( shippedData . NullableLineNumber > 0 )
383
386
{
384
387
// '#nullable enable' must be on the first line
385
388
errors . Add ( Diagnostic . Create ( descriptor , Location . None , InvalidReasonMisplacedNullableEnable ) ) ;
386
389
}
387
390
388
- if ( unshippedData . NullableRank > 0 )
391
+ if ( unshippedData . NullableLineNumber > 0 )
389
392
{
390
393
// '#nullable enable' must be on the first line
391
394
errors . Add ( Diagnostic . Create ( descriptor , Location . None , InvalidReasonMisplacedNullableEnable ) ) ;
0 commit comments