-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error for using positional member that is hidden #52660
Changes from 2 commits
2ef6e86
3b3a82b
9678fc3
0bf19ef
5baf897
22941d6
7da711e
4250456
fdf013a
8a3e2f0
cea1ac7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,10 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.Cci; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Roslyn.Utilities; | ||
|
||
|
@@ -17,18 +15,22 @@ internal sealed class SynthesizedRecordDeconstruct : SynthesizedRecordOrdinaryMe | |
{ | ||
private readonly SynthesizedRecordConstructor _ctor; | ||
private readonly ImmutableArray<PropertySymbol> _properties; | ||
private readonly ParameterListSyntax _parameters; | ||
|
||
public SynthesizedRecordDeconstruct( | ||
SourceMemberContainerTypeSymbol containingType, | ||
SynthesizedRecordConstructor ctor, | ||
ImmutableArray<PropertySymbol> properties, | ||
ParameterListSyntax parameters, | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int memberOffset, | ||
BindingDiagnosticBag diagnostics) | ||
: base(containingType, WellKnownMemberNames.DeconstructMethodName, hasBody: true, memberOffset, diagnostics) | ||
{ | ||
Debug.Assert(properties.All(prop => prop.GetMethod is object)); | ||
Debug.Assert(ctor.ParameterCount == parameters.ParameterCount); | ||
_ctor = ctor; | ||
_properties = properties; | ||
_parameters = parameters; | ||
} | ||
|
||
protected override DeclarationModifiers MakeDeclarationModifiers(DeclarationModifiers allowedModifiers, BindingDiagnosticBag diagnostics) | ||
|
@@ -59,6 +61,27 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray<ParameterSymb | |
|
||
protected override int GetParameterCountFromSyntax() => _ctor.ParameterCount; | ||
|
||
protected override void MethodChecks(BindingDiagnosticBag diagnostics) | ||
{ | ||
base.MethodChecks(diagnostics); | ||
|
||
if (ParameterCount == _properties.Length) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In reply to: 614614357 [](ancestors = 614614357) |
||
{ | ||
for (int i = 0; i < _properties.Length; i++) | ||
{ | ||
var property = _properties[i]; | ||
NamedTypeSymbol containingType = this.ContainingType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be moved outside the loop? #Resolved |
||
|
||
if (property.ContainingType != (object)containingType && | ||
!containingType.GetMembers(property.Name).IsEmpty) | ||
{ | ||
// The positional member was inherited but is hidden by a member of the current record type | ||
diagnostics.Add(ErrorCode.ERR_HiddenPositionalMember, _parameters.Parameters[i].Identifier.GetLocation(), property); | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} | ||
|
||
internal override void GenerateMethodBody(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics) | ||
{ | ||
var F = new SyntheticBoundNodeFactory(this, ContainingType.GetNonNullSyntaxNode(), compilationState, diagnostics); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.