@@ -303,13 +303,13 @@ bool IsPrimaryConstructor(Block body, IMethod method, IMethod unspecializedMetho
303303 continue ;
304304 if ( valueInst . MatchLdLoc ( out var v ) )
305305 {
306- if ( v . Kind != VariableKind . Parameter || v . Index < parameterIndex )
306+ if ( ! ValidateParameter ( v , parameterIndex ) )
307307 return false ;
308308 parameterIndex = v . Index ! . Value ;
309309 }
310310 else if ( valueInst . MatchLdObj ( out valueInst , out _ ) && valueInst . MatchLdLoc ( out v ) )
311311 {
312- if ( v . Kind != VariableKind . Parameter || v . Index < parameterIndex )
312+ if ( ! ValidateParameter ( v , parameterIndex ) )
313313 return false ;
314314 parameterIndex = v . Index ! . Value ;
315315 if ( method . Parameters [ parameterIndex ] . ReferenceKind is ReferenceKind . None )
@@ -339,6 +339,19 @@ bool IsPrimaryConstructor(Block body, IMethod method, IMethod unspecializedMetho
339339
340340 var returnInst = body . Instructions . LastOrDefault ( ) ;
341341 return returnInst != null && returnInst . MatchReturn ( out var retVal ) && retVal . MatchNop ( ) ;
342+
343+ bool ValidateParameter ( ILVariable v , int expectedMinimumIndex )
344+ {
345+ if ( v . Kind != VariableKind . Parameter )
346+ return false ;
347+ Debug . Assert ( v . Index . HasValue ) ;
348+ if ( v . Index < 0 || v . Index >= unspecializedMethod . Parameters . Count )
349+ return false ;
350+ var parameter = unspecializedMethod . Parameters [ v . Index . Value ] ;
351+ if ( primaryCtorParameterToAutoProperty . ContainsKey ( parameter ) )
352+ return true ;
353+ return v . Index >= expectedMinimumIndex ;
354+ }
342355 }
343356
344357 IMethod ? FindChainedCtor ( Block body )
0 commit comments