-
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
Binder Check for Unbound Generics in Methods #45033
Conversation
Looks like we fail an assert in DefiniteAssignmentPass. This should be reproducible locally by running the Microsoft.CodeAnalysis.CSharp.Symbol tests in Debug configuration. #Resolved |
src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs
Outdated
Show resolved
Hide resolved
Done review pass (commit 3). This doesn't seem like the right fix to me: It markedly degrades error experiences with unbound generics in some cases and doesn't hugely improve the scenario in the bug. I think we need to use a better error here. #Closed |
Edited the check to throw allow binding errors to occur, but adds a diagnostic to catch the new case. All instances where information density was reduced have been corrected, with the only issue being that there's occasionally one more descriptive error in the mix. #Resolved |
if (right is GenericNameSyntax genericNameRight && rightHasTypeArguments && typeArgumentsSyntax.Any(SyntaxKind.OmittedTypeArgument) && !IsUnboundTypeAllowed(genericNameRight)) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_UnexpectedUnboundGenericName, genericNameRight.Location); | ||
} |
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.
Nit: newline #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.
Broke the line at a reasonable point to improve readability. #Resolved
@@ -6062,6 +6062,11 @@ private bool IsUsingAliasInScope(string name) | |||
} | |||
default: | |||
{ | |||
// Ensure that there is an error thrown when an Unbound Generic is found. | |||
if (right is GenericNameSyntax genericNameRight && rightHasTypeArguments && typeArgumentsSyntax.Any(SyntaxKind.OmittedTypeArgument) && !IsUnboundTypeAllowed(genericNameRight)) |
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.
Do we need to do this for every default
case, or just the cases that return from here? #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.
You're right, only the ones that return from here need to be affected. Moved to a more specific scope. #Resolved
Done review pass (commit 4) #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.
LGTM (commit 5), assuming tests pass.
src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs
Outdated
Show resolved
Hide resolved
Done with review pass (iteration 5) #Closed |
Moved check code to |
src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs
Outdated
Show resolved
Hide resolved
|
||
static void M(I provider) | ||
{ | ||
provider.GetService<>(); |
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.
provider.GetService<>(); [](start = 8, length = 24)
This is not an invocation of a static method. A static method is qualified with a type name rather than with an instance. #Closed
src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/UnboundGenericType.vb
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
Outdated
Show resolved
Hide resolved
Done with review pass (iteration 6) #Closed |
Added new error, broadened error throwing to include all instances of OmittedTypeArgument in method binding.
Done with review pass (iteration 8). Implementation looks good to me. Consider adding recommended tests. #Closed |
Still getting used to CodeFlow, couldn't seem to find a way to drop a comment as the PR Author, gonna ask about that. |
~ | ||
</expected>) | ||
|
||
End Sub |
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.
Nit: extra newline below.
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 10)
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 (iteration 10)
Based off @RikkiGibson's #43130, a patch for issue #41779.
Thanks to @jpd30 for reporting the issue!
This patch checks for unbound types in the Binder, throwing a CS7003 error without needing to run EmitDiagnostics.
Changelog:
Added check to Binder_Expression.cs
Added test for issue Emit a more specific error when using the null suppression operator on a Nullable<T> #41799.
Edited tests to throw new error when applicable.
Sidenote: Apologies for the messy git changes to some of those tests. The newer outputs from the testing suite contained more information in comments that I thought would be worthwhile to leave in.