ERR_ImplBadTupleNames is now being reported in correct class#24438
ERR_ImplBadTupleNames is now being reported in correct class#24438t-camaia merged 6 commits intodotnet:dev15.7.xfrom
Conversation
|
@t-camaia can you retarget this PR to dev15.7.x? |
| } | ||
| else | ||
| { | ||
| diagnostics.Add(ErrorCode.ERR_ImplBadTupleNames, implementingType.Locations[0], implicitImpl, interfaceMember); |
There was a problem hiding this comment.
implementingType.Locations[0] [](start = 69, length = 29)
I think the location should be the interface reference in the base list, we probably already have a helper that finds it. #Closed
There was a problem hiding this comment.
Take a look at the logic around error location in ReportImplicitImplementationMismatchDiagnostics method in this file. See if we can share it with this method. #Closed
It looks like other errors reported in this function have the same issue, I think we should fix all of them #Closed Refers to: src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs:1041 in ba19c27. [](commit_id = ba19c27, deletion_comment = False) |
| { | ||
| // it is ok to implement implicitly with no tuple names, for compatibility with C# 6, but otherwise names should match | ||
| diagnostics.Add(ErrorCode.ERR_ImplBadTupleNames, implicitImpl.Locations[0], implicitImpl, interfaceMember); | ||
| if (implicitImpl.ContainingType == implementingType) |
There was a problem hiding this comment.
if (implicitImpl.ContainingType == implementingType) [](start = 16, length = 52)
Rather than adding a branching that pretty much duplicates the code with some minor variation, consider adding a local function that will return the right location based on conditional logic inside it. #Closed
|
Done with review pass (iteration 1) #Closed |
|
@AlekseyTs I believe the other errors could only happen with explicit implementations, which means they are always being reported in the expected location. Do you have any particular scenario in mind? |
The function is named ReportImplicitImplementationMatchDiagnostics I would be surprised if it was reporting errors for an explicit implementation #Closed |
| { | ||
| var @interface = interfaceMember.ContainingType; | ||
| SourceMemberContainerTypeSymbol snt = implementingType as SourceMemberContainerTypeSymbol; | ||
| return snt.GetImplementsLocation(@interface) ?? implementingType.Locations[0]; |
There was a problem hiding this comment.
snt. [](start = 31, length = 4)
It feels like this access should be conditional because snt can be null. We should fix the other call site as well #Closed
There was a problem hiding this comment.
This could be rewritten as return (implementingType as SourceMemberContainerTypeSymbol)?.GetImplementsLocation(@interface) ?? implementingType.Locations[0]
|
Done with review pass (iteration 2) #Closed |
…face reference. Tests updated.
| } | ||
| } | ||
|
|
||
| Location GetDiagnosticLocation(Symbol member) |
There was a problem hiding this comment.
It's only a local function. I believe it's not possible to mark it with access modifiers.
There was a problem hiding this comment.
I'll put it at the beginning of the method to avoid confusion.
| } | ||
| } | ||
|
|
||
| Location GetDiagnosticLocation(Symbol member) |
There was a problem hiding this comment.
Symbol member [](start = 43, length = 13)
It feels strange that we are passing a member, but not passing implementingType and interfaceMember . Consider either passing all, or neither. #Closed
There was a problem hiding this comment.
We are only passing a member because WRN_MultipleRuntimeImplementationMatches may be reported in a location different from implicitImpl.
| } | ||
| } | ||
|
|
||
| Location GetDiagnosticLocation(Symbol member) |
There was a problem hiding this comment.
GetDiagnosticLocation [](start = 21, length = 21)
I think our naming convention for local function requires them to start with small letter, i.e. "getDiagnosticLocation". #Closed
It looks like we might want to adjust location for errors reported by this function as well. #Closed Refers to: src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs:1068 in 179ee37. [](commit_id = 179ee37, deletion_comment = False) |
|
Done with review pass (iteration 3) #Closed |
…od report location updated. Tests updated.
| else | ||
| { | ||
| ReportAnyMismatchedConstraints(interfaceMethod, implementingType, implicitImplMethod, diagnostics); | ||
| ReportAnyMismatchedConstraints(interfaceMethod, implementingType, implicitImplMethod, getDiagnosticLocation(implicitImpl), diagnostics); |
There was a problem hiding this comment.
getDiagnosticLocation(implicitImpl) [](start = 110, length = 35)
We should avoid eager calculation of location before we determined that there is any diagnostics to report. We probably should make getDiagnosticLocation a real (non-local) static function and call it inside ReportAnyMismatchedConstraints when location is needed. #Closed
|
Done with review pass (iteration 4) #Closed |
|
@dotnet-bot retest this please |
| } | ||
| } | ||
|
|
||
| private static Location GetDiagnosticLocation(Symbol interfaceMember, TypeSymbol implementingType, Symbol member) |
There was a problem hiding this comment.
GetDiagnosticLocation [](start = 32, length = 21)
GetImplicitImplementationDiagnosticLocation?
An if statement was added to check whether we should report ERR_ImplBadTupleNames in the method or in the class declaration. Some tests were also updated.
Fixes #20897.