-
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
Enable out variables in indexers, and implement lazy inference of pattern variables. #13274
Conversation
…tern variables. Also eliminates some cases of cascaded definite assignment errors. Fixes dotnet#13219 Fixes dotnet#13009 Fixes dotnet#12996 Fixes dotnet#10446
…e used to initialize its storage.
var x = d[out int z]; | ||
} | ||
}"; | ||
// the C# dynamic binder does not support ref or out indexers, so we don't run this |
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.
If the dynamic binder doesn't support ref or out indexers, why doesn't the compiler report an error? #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.
Because the C# (static) compiler doesn't know if a variable of type dynamic
uses the C# dynamic binder or a custom binder. #Resolved
LGTM |
Plus a couple of other minor changes per code review.
/// <param name="declarationKind"></param> | ||
/// <param name="context">The expression to be bound, which will result in the variable receiving a type</param> | ||
/// <returns></returns> | ||
public static SourceLocalSymbol MakeVariableDeclaredInExpression( |
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.
MakeVariableDeclaredInExpression [](start = 40, length = 32)
The doc comment says this function is specific for "out" locals, but the name doesn't reflect this. Is there a particular reason for this? #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.
I will update the comment. It is for any variable whose type is inferred as a side-effect of binding an expression.
In reply to: 75756408 [](ancestors = 75756408)
Please add a test that verifies that an attempt to infer type of this local without binding this statement first produces expected result. #Closed Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs:14321 in c3d5c38. [](commit_id = c3d5c38, deletion_comment = False) |
@@ -14591,5 +14575,199 @@ static int Test1(out int x) | |||
|
|||
Assert.Equal("System.Int32", model.GetTypeInfo(yRef).Type.ToTestDisplayString()); | |||
} | |||
|
|||
[Fact, WorkItem(13219, "https://github.com/dotnet/roslyn/issues/13219")] | |||
public void IndexingDynamic() |
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.
IndexingDynamic [](start = 20, length = 15)
Please add test for scenario that uses var
as type.
Please add verification for SemanticModel behavior.
Please add specific test for type inference before the indexing is bound. #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.
The thread is marked as resolved, but it doesn't look like there is a "specific test for type inference before the indexing is bound". What am I missing?
In reply to: 75763457 [](ancestors = 75763457)
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 am going to add tests for fixed field initializers, and any code required to make that work. #Resolved |
@dotnet/roslyn-compiler May I please have a second review? #Resolved |
LGTM |
|
||
public override void VisitDeconstructionDeclarationStatement(DeconstructionDeclarationStatementSyntax node) | ||
{ | ||
VisitNodeToBind(node.Assignment.Value); |
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.
VisitNodeToBind(node.Assignment.Value); [](start = 12, length = 39)
Is this code really used?
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 guess tools are confused. In reply to: 243521804 [](ancestors = 243521804,243520839) Refers to: src/Compilers/CSharp/Portable/Binder/LocalScopeBinder.cs:184 in e4b4af9. [](commit_id = e4b4af9, deletion_comment = False) |
break; | ||
|
||
case SyntaxKind.ForStatement: | ||
var forStatement = (ForStatementSyntax)_deconstruction; | ||
var forBinder = this.ScopeBinder.GetBinder(forStatement); | ||
forBinder.BindDeconstructionDeclaration(forStatement, forStatement.Deconstruction.VariableComponent, forStatement.Deconstruction.Value, diagnostics); | ||
Debug.Assert(this.ScopeBinder.GetBinder(forStatement) == _nodeBinder); |
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.
Debug.Assert(this.ScopeBinder.GetBinder(forStatement) == _nodeBinder); [](start = 24, length = 70)
Do we have a test hitting this code path? #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.
The same tests that hit this switch branch previously.
In reply to: 76849261 [](ancestors = 76849261)
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.
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.
Also eliminates some cases of cascaded definite assignment errors.
Fixes #13219
Fixes #13009
Fixes #12996
Fixes #10446
@agocke @AlekseyTs Please review
/cc @dotnet/roslyn-compiler FYI