@@ -3668,12 +3668,7 @@ void mergePartialMethods(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<Sym
3668
3668
}
3669
3669
else
3670
3670
{
3671
- if ( ( object ) membersByName == _lazyEarlyAttributeDecodingMembersDictionary )
3672
- {
3673
- // Avoid mutating the cached dictionary and especially avoid doing this possibly on multiple threads in parallel.
3674
- membersByName = new Dictionary < ReadOnlyMemory < char > , ImmutableArray < Symbol > > ( membersByName , ReadOnlyMemoryOfCharComparer . Instance ) ;
3675
- }
3676
-
3671
+ DuplicateMembersByNameIfCached ( ref membersByName ) ;
3677
3672
membersByName [ name ] = FixPartialMember ( membersByName [ name ] , prevMethod , currentMethod ) ;
3678
3673
}
3679
3674
}
@@ -3692,40 +3687,23 @@ void mergePartialProperties(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<
3692
3687
}
3693
3688
else
3694
3689
{
3695
- var ( currentGet , prevGet ) = ( ( SourcePropertyAccessorSymbol ? ) currentProperty . GetMethod , ( SourcePropertyAccessorSymbol ? ) prevProperty . GetMethod ) ;
3696
- if ( currentGet != null || prevGet != null )
3697
- {
3698
- var accessorName = ( currentGet ?? prevGet ) ! . Name . AsMemory ( ) ;
3699
- mergeAccessors ( ref membersByName , accessorName , currentGet , prevGet ) ;
3700
- }
3701
-
3702
- var ( currentSet , prevSet ) = ( ( SourcePropertyAccessorSymbol ? ) currentProperty . SetMethod , ( SourcePropertyAccessorSymbol ? ) prevProperty . SetMethod ) ;
3703
- if ( currentSet != null || prevSet != null )
3704
- {
3705
- var accessorName = ( currentSet ?? prevSet ) ! . Name . AsMemory ( ) ;
3706
- mergeAccessors ( ref membersByName , accessorName , currentSet , prevSet ) ;
3707
- }
3708
-
3709
- if ( ( object ) membersByName == _lazyEarlyAttributeDecodingMembersDictionary )
3710
- {
3711
- // Avoid mutating the cached dictionary and especially avoid doing this possibly on multiple threads in parallel.
3712
- membersByName = new Dictionary < ReadOnlyMemory < char > , ImmutableArray < Symbol > > ( membersByName , ReadOnlyMemoryOfCharComparer . Instance ) ;
3713
- }
3714
-
3690
+ DuplicateMembersByNameIfCached ( ref membersByName ) ;
3691
+ mergeAccessors ( ref membersByName , ( SourcePropertyAccessorSymbol ? ) currentProperty . GetMethod , ( SourcePropertyAccessorSymbol ? ) prevProperty . GetMethod ) ;
3692
+ mergeAccessors ( ref membersByName , ( SourcePropertyAccessorSymbol ? ) currentProperty . SetMethod , ( SourcePropertyAccessorSymbol ? ) prevProperty . SetMethod ) ;
3715
3693
membersByName [ name ] = FixPartialMember ( membersByName [ name ] , prevProperty , currentProperty ) ;
3716
3694
}
3717
3695
3718
- void mergeAccessors ( ref Dictionary < ReadOnlyMemory < char > , ImmutableArray < Symbol > > membersByName , ReadOnlyMemory < char > name , SourcePropertyAccessorSymbol ? currentAccessor , SourcePropertyAccessorSymbol ? prevAccessor )
3696
+ void mergeAccessors ( ref Dictionary < ReadOnlyMemory < char > , ImmutableArray < Symbol > > membersByName , SourcePropertyAccessorSymbol ? currentAccessor , SourcePropertyAccessorSymbol ? prevAccessor )
3719
3697
{
3720
- Debug . Assert ( currentAccessor != null || prevAccessor != null ) ;
3721
- if ( currentAccessor != null && prevAccessor != null )
3698
+ if ( currentAccessor is { } && prevAccessor is { } )
3722
3699
{
3700
+ var name = currentAccessor . Name . AsMemory ( ) ;
3723
3701
var implementationAccessor = currentProperty . IsPartialDefinition ? prevAccessor : currentAccessor ;
3724
3702
membersByName [ name ] = Remove ( membersByName [ name ] , implementationAccessor ) ;
3725
3703
}
3726
- else
3704
+ else if ( currentAccessor is { } || prevAccessor is { } )
3727
3705
{
3728
- var ( foundAccessor , containingProperty , otherProperty ) = prevAccessor != null ? ( prevAccessor , prevProperty , currentProperty ) : ( currentAccessor ! , currentProperty , prevProperty ) ;
3706
+ var ( foundAccessor , containingProperty , otherProperty ) = prevAccessor is { } ? ( prevAccessor , prevProperty , currentProperty ) : ( currentAccessor ! , currentProperty , prevProperty ) ;
3729
3707
// When an accessor is present on definition but not on implementation, the accessor is said to be missing on the implementation.
3730
3708
// When an accessor is present on implementation but not on definition, the accessor is said to be unexpected on the implementation.
3731
3709
var ( errorCode , propertyToBlame ) = foundAccessor . IsPartialDefinition
@@ -3737,6 +3715,15 @@ void mergeAccessors(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<Symbol>>
3737
3715
}
3738
3716
}
3739
3717
3718
+ private void DuplicateMembersByNameIfCached ( ref Dictionary < ReadOnlyMemory < char > , ImmutableArray < Symbol > > membersByName )
3719
+ {
3720
+ if ( ( object ) membersByName == _lazyEarlyAttributeDecodingMembersDictionary )
3721
+ {
3722
+ // Avoid mutating the cached dictionary and especially avoid doing this possibly on multiple threads in parallel.
3723
+ membersByName = new Dictionary < ReadOnlyMemory < char > , ImmutableArray < Symbol > > ( membersByName , ReadOnlyMemoryOfCharComparer . Instance ) ;
3724
+ }
3725
+ }
3726
+
3740
3727
/// <summary>Links together the definition and implementation parts of a partial method. Returns a member list which has the implementation part removed.</summary>
3741
3728
private static ImmutableArray < Symbol > FixPartialMember ( ImmutableArray < Symbol > symbols , SourceOrdinaryMethodSymbol part1 , SourceOrdinaryMethodSymbol part2 )
3742
3729
{
0 commit comments