-
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
Have compiler return semantic errors in lambdas even in the presence of syntax errors #1867
Comments
The compiler does not generate semantic errors inside lambdas in the presence of syntactic errors causing several features to not work in lambdas with syntax errors. The bug for this ([1867](dotnet#1867)) was moved to milestone 1.1 so we are going to use an analyzer in the interim for 1.0. 1. We now check for IncompleteMemberSyntax nodes and LambdaExpressionSyntax nodes which contain syntax diagnostics on any of their descendant nodes. 2. We report both unbound identifier names and constructors that the compiler reports as binding, but which fail overload resolution (actually don't exist). Performance considerations should be mitigated by only doing these checks only lambdas with syntax errors. Other notes: - Renamed analyzer to UnboundIdentifier instead of AddImport since it is being used in more places than just the AddImport fixer - Updated the DiagnosticDescriptor for this analyzer to take localizeable strings. Fixes dotnet#1744 Fixes dotnet#1241 Fixes dotnet#1239
Note: whenever this is fixed we need to remove the UnboundIdentifiersDiagnosticAnalyzerBase type and ensure all AddUsing tests (and other tests that depend on this type) still continue passing. Right now, this type is a hack at the IDE layer to get and display reasonable semantic errors to the user and to drive our normal features. This should not be something the IDE is responsible for doing. Users should be getting these errors, even in the presence of a syntax error in a lambda, and our features should not have to list for syntax errors to drive semantic features. |
Reactivating. Here are cases where we still don't get errors from the compiler: using System.Linq;
class C { C() { "".Select(() => { new Byte //<-- no error on Byte
class D { D() { "".Select(() => { new Byte ( ) } //<-- no error on Byte
class Program
{
static void Main(string[] args)
{
args[0].Any(x => IBindCtx // <-- no error on IBindCtx
string a;
}
} |
For the first two cases, the compiler certainly does produce a semantic error about Working on the third case. |
OK, in the third case we have a lambda of the form e.Any(x => identifier string identifier; // and more broken syntax and you're complaining that we don't give an error that we can't bind the first identifier? What are you imagining the compiler would be trying to bind it for? It simply doesn't line up with any recognizable expression form. |
Here is a better repro for the third case: args[0].Any(x => IBindCtx, foo foo); Here we should give an error that we can't bind IBindCtx. |
…ils. Also reduce cascaded diagnostics in lambdas inside queries. Fixes dotnet#1867
OK, PR #7555 addresses all the new cases. |
…ils. Also reduce cascaded diagnostics in lambdas inside queries. Fixes dotnet#1867
@CyrusNajmabadi OK, all fixed. I'm eager to catch as many of these cases as possible. You're welcome to open new issues for any new cases you discover. |
@gafter Will do. Thanks! |
Today, the compiler does not return semantic errors inside lambdas in the IDE if there are syntax errors. This causes several quick fix scenarios to fail inside lambdas (for example #1239, #1241, and #1744 are all caused by this problem).
Consider the code sample below from issue #1239:
new C(0) will never be squiggled by the IDE because of the lack of a semicolon. This makes quick-fixes that could generate a constructor unable to run because there is no error to trigger them.
By having the compiler return semantic errors in lambdas even in the presence of syntax errors, many more IDE scenarios will "Just Work"
The text was updated successfully, but these errors were encountered: