-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Conversation
{ | ||
public int I { get; init; } | ||
} | ||
record Derived(int I) // error: The positional member `Base.I` found corresponding to parameter `I` is hidden. |
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.
record Derived(int I) // error: The positional member `Base.I` found corresponding to parameter `I` is hidden. | |
record Derived(int I) // error: The positional member 'Base.I' found corresponding to this parameter is hidden. | |
``` #Resolved |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Could be moved outside the loop? #Resolved
{ | ||
base.MethodChecks(diagnostics); | ||
|
||
if (ParameterCount == _properties.Length) |
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.
-
When can the this condition be false?
-
What if the Deconstruct method is declared explicitly:
public record Base { public int I { get; set; } = 42; public Base(int ignored) { } public void Deconstruct(out string s, out string s2) { s = s2 = ""; } } public record C(int I) : Base(I) { public void I() { } public void Deconstruct(out string s, out string s2) { s = s2 = ""; } } ``` #Resolved
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.
- the condition is false when
addProperties
inSourceMemberContainerSymbol
doesn't find a property for each parameter (we produceERR_BadRecordMemberForPositionalParameter
in that case). - thanks. I need to think more about scenarios where
Deconstruct
is declared in source. We should produce a diagnostic too, but currently don't.
In reply to: 614614357 [](ancestors = 614614357)
src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordDeconstruct.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordDeconstruct.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
Outdated
Show resolved
Hide resolved
|
||
if (isInherited) | ||
{ | ||
validateNotHidden(prop, param); |
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.
If prop
is abstract, it won't be validated, is that intended? i.e:
abstract record Base
{
public abstract int I { get; init; }
}
record Derived(int I) : Base
{
public int I() { return 0; }
}
#Resolved
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.
In that scenario Derived
defined a concrete property I
and a method I()
(that's an error). The positional member is Derived.I
so we didn't pick a hidden member, so the new error doesn't come into play.
Added tests to illustrate. Thanks for the scenario. #Resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
Show resolved
Hide resolved
Done with review pass (commit 9) In reply to: 822644422 |
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.
LGTM (commit 11)
Fixes #52630
Relates to test plan: #51199
Spec change: dotnet/csharplang#4673