Skip to content
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

Merged
merged 14 commits into from
Aug 30, 2016

Conversation

gafter
Copy link
Member

@gafter gafter commented Aug 19, 2016

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

var x = d[out int z];
}
}";
// the C# dynamic binder does not support ref or out indexers, so we don't run this
Copy link
Member

@cston cston Aug 22, 2016

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

Copy link
Member Author

@gafter gafter Aug 22, 2016

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

@cston
Copy link
Member

cston commented Aug 22, 2016

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(
Copy link
Contributor

@AlekseyTs AlekseyTs Aug 22, 2016

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

Copy link
Member Author

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)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Aug 22, 2016

    Test2(x[out var x1], x1);

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()
Copy link
Contributor

@AlekseyTs AlekseyTs Aug 22, 2016

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

Copy link
Contributor

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've marked the place you were missing.


In reply to: 75921906 [](ancestors = 75921906,75763457)

@gafter
Copy link
Member Author

gafter commented Aug 26, 2016

I am going to add tests for fixed field initializers, and any code required to make that work. #Resolved

@gafter
Copy link
Member Author

gafter commented Aug 26, 2016

Actually, I just filed an issue for it. #13417


In reply to: 242868130 [](ancestors = 242868130)

@gafter
Copy link
Member Author

gafter commented Aug 29, 2016

@dotnet/roslyn-compiler May I please have a second review? #Resolved

@VSadov
Copy link
Member

VSadov commented Aug 29, 2016

:shipit:

@agocke
Copy link
Member

agocke commented Aug 30, 2016

LGTM


public override void VisitDeconstructionDeclarationStatement(DeconstructionDeclarationStatementSyntax node)
{
VisitNodeToBind(node.Assignment.Value);
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not I'll remove it in a subsequent PR.


In reply to: 76841816 [](ancestors = 76841816)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Aug 30, 2016

                        enclosingBinder = enclosingBinder.GetBinder(innerStatement) ?? enclosingBinder;

This change doesn't look right, we should not be overriding enclosingBinder. #Closed


Refers to: src/Compilers/CSharp/Portable/Binder/LocalScopeBinder.cs:184 in e4b4af9. [](commit_id = e4b4af9, deletion_comment = False)

@gafter
Copy link
Member Author

gafter commented Aug 30, 2016

                        enclosingBinder = enclosingBinder.GetBinder(innerStatement) ?? enclosingBinder;

This isn't a change in this PR.


In reply to: 243520839 [](ancestors = 243520839)


Refers to: src/Compilers/CSharp/Portable/Binder/LocalScopeBinder.cs:184 in e4b4af9. [](commit_id = e4b4af9, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

                        enclosingBinder = enclosingBinder.GetBinder(innerStatement) ?? enclosingBinder;

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);
Copy link
Contributor

@AlekseyTs AlekseyTs Aug 30, 2016

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

Copy link
Member Author

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any?


In reply to: 76852705 [](ancestors = 76852705,76849261)

Copy link
Member Author

@gafter gafter Aug 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Since you don't know, I'll open an issue about test coverage for this case.

Filed as #13458


In reply to: 76854336 [](ancestors = 76854336,76852705,76849261)

@AlekseyTs
Copy link
Contributor

        var model = compilation.GetSemanticModel(tree);

It looks like the local is not used.


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs:14245 in a938f65. [](commit_id = a938f65, deletion_comment = False)

@gafter
Copy link
Member Author

gafter commented Aug 30, 2016

        var model = compilation.GetSemanticModel(tree);

I'll remove it in some future PR.


In reply to: 243539241 [](ancestors = 243539241)


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs:14245 in a938f65. [](commit_id = a938f65, deletion_comment = False)

@gafter gafter merged commit c484138 into dotnet:master Aug 30, 2016
@markwilkie markwilkie removed the Bug label Aug 30, 2016
@gafter gafter added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Aug 30, 2016
@gafter gafter deleted the master-13219 branch May 24, 2018 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers cla-already-signed New Language Feature - Out Variable Declaration Out Variable Declaration New Language Feature - Pattern Matching Pattern Matching Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants