-
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
Bind lambda in object initializer despite errors #75695
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e6796a3
Bind lambda in initializer despite errors
jcouv b5969c2
Alternative approach
jcouv 7465ddd
Revert "Alternative approach"
jcouv c14a513
update test
jcouv c63c6f7
Adjust BindAssignment instead
jcouv a9d0384
Simplify BindYieldReturnStatement
jcouv e5b15c9
Remove TODO comment
jcouv d27db71
Revert some test files
jcouv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4168,24 +4168,24 @@ public static void Main() | |
string expectedOperationTree = @" | ||
IInvalidOperation (OperationKind.Invalid, Type: ?, IsInvalid) (Syntax: 'new ref[] { 1 }') | ||
Children(1): | ||
IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: ?[]) (Syntax: '{ 1 }') | ||
IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: ?[], IsInvalid) (Syntax: '{ 1 }') | ||
Initializers(1): | ||
IInvalidOperation (OperationKind.Invalid, Type: ?, IsImplicit) (Syntax: '1') | ||
Children(2): | ||
IOperation: (OperationKind.None, Type: null, IsImplicit) (Syntax: '1') | ||
Children(1): | ||
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: ?[], IsInvalid, IsImplicit) (Syntax: 'ref[]') | ||
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') | ||
IInvalidOperation (OperationKind.Invalid, Type: ?, IsInvalid, IsImplicit) (Syntax: '1') | ||
Children(1): | ||
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1, IsInvalid) (Syntax: '1') | ||
"; | ||
|
||
var expectedDiagnostics = new[] | ||
{ | ||
// file.cs(6,28): error CS8386: Invalid object creation | ||
// (6,28): error CS8386: Invalid object creation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// _ = /*<bind>*/ new ref[] { 1 } /*</bind>*/ ; | ||
Diagnostic(ErrorCode.ERR_InvalidObjectCreation, "ref[]").WithLocation(6, 28), | ||
// file.cs(6,31): error CS1031: Type expected | ||
// (6,31): error CS1031: Type expected | ||
// _ = /*<bind>*/ new ref[] { 1 } /*</bind>*/ ; | ||
Diagnostic(ErrorCode.ERR_TypeExpected, "[").WithLocation(6, 31) | ||
Diagnostic(ErrorCode.ERR_TypeExpected, "[").WithLocation(6, 31), | ||
// (6,36): error CS1061: '?[]' does not contain a definition for 'Add' and no accessible extension method 'Add' accepting a first argument of type '?[]' could be found (are you missing a using directive or an assembly reference?) | ||
// _ = /*<bind>*/ new ref[] { 1 } /*</bind>*/ ; | ||
Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "1").WithArguments("?[]", "Add").WithLocation(6, 36) | ||
}; | ||
|
||
VerifyOperationTreeAndDiagnosticsForTest<ObjectCreationExpressionSyntax>(text, expectedOperationTree, expectedDiagnostics); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While I do not object to making this change, it feels like this is not a fix for the problem the PR is claiming to address. In order for SemanticModel to work properly, every syntax node that is normally bindable should be bound, regardless of errors, That means that the value returned by this helper shouldn't matter. The lambda should be bound even if this helper returns true. #Closed
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.
We might suppress additional diagnostics based on what this helper returns, but we should not be suppressing the binding.
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.
I can adjust the PR title if that's what you're suggesting. Like in another lambda-related PR last week, the question is whether we do
BindToTypeForErrorRecovery
(which results in poor lambda binding) orGenerateConversionForAssignment
(which binds a conversion so results in better lambda information).Maybe "Adjust lambda binding in object initializer despite errors"?