-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align addition of a synthesized override of object.Equals(object? obj…
…) in records with the latest design. (#45475) * Align addition of a synthesized override of object.Equals(object? obj) in records with the latest design. Related to #45296. From specification: The record type includes a synthesized override of object.Equals(object? obj). It is an error if the override is declared explicitly. The synthesized override returns Equals(other as R) where R is the record type.
- Loading branch information
Showing
25 changed files
with
680 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordObjectMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#nullable enable | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
{ | ||
/// <summary> | ||
/// Common base for ordinary methods overriding methods from object synthesized by compiler for records. | ||
/// </summary> | ||
internal abstract class SynthesizedRecordObjectMethod : SynthesizedRecordOrdinaryMethod | ||
{ | ||
protected SynthesizedRecordObjectMethod(SourceMemberContainerTypeSymbol containingType, string name, int memberOffset, DiagnosticBag diagnostics) | ||
: base(containingType, name, memberOffset, diagnostics) | ||
{ | ||
} | ||
|
||
protected sealed override void MethodChecks(DiagnosticBag diagnostics) | ||
{ | ||
base.MethodChecks(diagnostics); | ||
|
||
var overridden = OverriddenMethod?.OriginalDefinition; | ||
|
||
if (overridden is null || (overridden is SynthesizedRecordObjEquals && overridden.DeclaringCompilation == DeclaringCompilation)) | ||
{ | ||
return; | ||
} | ||
|
||
MethodSymbol leastOverridden = GetLeastOverriddenMethod(accessingTypeOpt: null); | ||
|
||
if (leastOverridden is object && | ||
leastOverridden.ReturnType.SpecialType == ReturnType.SpecialType && | ||
leastOverridden.ContainingType.SpecialType != SpecialType.System_Object) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_DoesNotOverrideMethodFromObject, Locations[0], this); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.