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.
| 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.
Could be moved outside the loop? #Resolved
| { | ||
| base.MethodChecks(diagnostics); | ||
|
|
||
| if (ParameterCount == _properties.Length) |
There was a problem hiding this comment.
-
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.
- the condition is false when
addPropertiesinSourceMemberContainerSymboldoesn't find a property for each parameter (we produceERR_BadRecordMemberForPositionalParameterin that case). - thanks. I need to think more about scenarios where
Deconstructis 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.
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.
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 |
Fixes #52630
Relates to test plan: #51199
Spec change: dotnet/csharplang#4673