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

Move reporting of ERR_IteratorMustBeAsync to avoid race condition #39990

Merged
merged 7 commits into from
Nov 26, 2019

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Nov 23, 2019

Fixes #39970
Fixes #39992

@jcouv jcouv requested a review from a team as a code owner November 23, 2019 00:33
@jcouv jcouv self-assigned this Nov 23, 2019
@jcouv jcouv added this to the 16.5 milestone Nov 23, 2019
@@ -162,10 +161,6 @@ internal override TypeWithAnnotations GetIteratorElementType(YieldStatementSynta
}
elementType = TypeWithAnnotations.Create(CreateErrorType());
}
else if (asyncInterface && !_methodSymbol.IsAsync)
{
Error(elementTypeDiagnostics, ErrorCode.ERR_IteratorMustBeAsync, errorLocation, _methodSymbol, returnType);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2019

Choose a reason for hiding this comment

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

Error(elementTypeDiagnostics, ErrorCode.ERR_IteratorMustBeAsync, errorLocation, _methodSymbol, returnType); [](start = 20, length = 107)

Can we get into similar trouble with errors reported above? #Closed

Copy link
Member Author

@jcouv jcouv Nov 25, 2019

Choose a reason for hiding this comment

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

I think so, yes. #39992 is indeed similar. I'll address in this PR. Thanks! #Resolved

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 23, 2019

Could you please check if #39992 is the same/similar issue? #Closed

@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Nov 25, 2019
@@ -14594,6 +14594,7 @@ public static void Main()
// public IEnumerator GetEnumerator()
Diagnostic(ErrorCode.ERR_ReturnExpected, "GetEnumerator").WithArguments("C.GetEnumerator()")
);
comp.GetEmitDiagnostics();
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 25, 2019

Choose a reason for hiding this comment

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

GetEmitDiagnostics [](start = 17, length = 18)

VerifyEmitDiagnostics? #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 25, 2019

    internal override TypeWithAnnotations GetIteratorElementType(YieldStatementSyntax node, DiagnosticBag diagnostics)

It looks like this parameter is no longer used. #Closed


Refers to: src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs:127 in 10d359f. [](commit_id = 10d359f, deletion_comment = False)

@@ -1897,6 +1898,7 @@ static System.Collections.Generic.IAsyncEnumerable<int> M()
// static System.Collections.Generic.IAsyncEnumerable<int> M()
Diagnostic(ErrorCode.ERR_IteratorMustBeAsync, "M").WithArguments("C.M()", "System.Collections.Generic.IAsyncEnumerable<int>").WithLocation(4, 61)
);
comp.GetEmitDiagnostics();
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 25, 2019

Choose a reason for hiding this comment

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

GetEmitDiagnostics [](start = 17, length = 18)

VerifyEmitDiagnostics? #Closed

@@ -2244,6 +2245,8 @@ public static int Main()
}
}";
var compilation = CreateCompilation(text);
compilation.GetDiagnostics();
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 25, 2019

Choose a reason for hiding this comment

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

GetDiagnostics [](start = 24, length = 14)

Verify? #Closed

@@ -2244,6 +2245,8 @@ public static int Main()
}
}";
var compilation = CreateCompilation(text);
compilation.GetDiagnostics();
compilation.GetEmitDiagnostics();
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 25, 2019

Choose a reason for hiding this comment

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

GetEmitDiagnostics [](start = 24, length = 18)

Verify? #Closed

@@ -2244,6 +2245,8 @@ public static int Main()
}
}";
var compilation = CreateCompilation(text);
compilation.GetDiagnostics();
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 25, 2019

Choose a reason for hiding this comment

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

compilation.GetDiagnostics(); [](start = 12, length = 29)

Instead of modifying this particular unit-test, consider creating a new one. It looks like the original test is targeting specific sequence of API calls. #Closed

@@ -23,15 +23,13 @@ internal sealed class InMethodBinder : LocalScopeBinder

private class IteratorInfo
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 25, 2019

Choose a reason for hiding this comment

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

IteratorInfo [](start = 22, length = 12)

Can we use TypeWithAnnotations.Boxed instead of this class now? #Closed

@jcouv
Copy link
Member Author

jcouv commented Nov 25, 2019

    internal override TypeWithAnnotations GetIteratorElementType(YieldStatementSyntax node, DiagnosticBag diagnostics)

It's used in the override in WithLambdaParametersBinder


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


Refers to: src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs:127 in 10d359f. [](commit_id = 10d359f, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

    internal override TypeWithAnnotations GetIteratorElementType(YieldStatementSyntax node, DiagnosticBag diagnostics)

It's used in the override in WithLambdaParametersBinder

Would it make sense to move reporting of ERR_YieldInAnonMeth to methods that bind YieldStatementSyntax?


In reply to: 558389580 [](ancestors = 558389580,558375087)


Refers to: src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs:127 in 10d359f. [](commit_id = 10d359f, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 25, 2019

    internal override TypeWithAnnotations GetIteratorElementType(YieldStatementSyntax node, DiagnosticBag diagnostics)

It feels like we can get rid of this parameter as well. #Closed


Refers to: src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs:127 in 10d359f. [](commit_id = 10d359f, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 26, 2019

Done with review pass (iteration 3) #Closed

@@ -13,27 +13,15 @@ namespace Microsoft.CodeAnalysis.CSharp
/// <summary>
/// A binder for a method body, which places the method's parameters in scope
/// and notes if the method is an iterator method.
/// Note: instances of this type can be re-used across different attempts at compiling the same method (caching by binder factory).
Copy link
Member Author

Choose a reason for hiding this comment

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

Note [](start = 8, length = 4)

📝 I didn't find any other diagnostics stored in this binder.

@@ -261,7 +265,8 @@ private BoundStatement BindYieldBreakStatement(YieldStatementSyntax node, Diagno
Error(diagnostics, ErrorCode.ERR_YieldNotAllowedInScript, node.YieldKeyword);
}

GetIteratorElementType(node, diagnostics);
ValidateYield(node, diagnostics);
GetIteratorElementType();
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 26, 2019

Choose a reason for hiding this comment

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

GetIteratorElementType(); [](start = 12, length = 25)

It looks like this call is not necessary now. #Closed

@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Nov 26, 2019
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 5)

Copy link
Contributor

@chsienki chsienki left a comment

Choose a reason for hiding this comment

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

:shipit:

@jcouv jcouv merged commit e2f6bf3 into dotnet:master Nov 26, 2019
@jcouv jcouv deleted the cancellation-token2 branch November 26, 2019 18:21
@jcouv jcouv modified the milestones: 16.5, 16.5.P1 Nov 26, 2019
333fred added a commit to 333fred/roslyn that referenced this pull request Dec 2, 2019
…ointers

* dotnet/master: (197 commits)
  Update dependencies from https:/dotnet/arcade build 20191201.1 (dotnet#40084)
  Update list of C# Next features and reviewers (dotnet#39987)
  Update dependencies from https:/dotnet/arcade build 20191130.1 (dotnet#40075)
  [master] Update dependencies from dotnet/arcade (dotnet#40065)
  Update dependencies from https:/dotnet/arcade build 20191127.4 (dotnet#40057)
  Added more tests & fixed minor bug
  Deterministic ordering + added tests back
  Update dependencies from https:/dotnet/arcade build 20191126.2 (dotnet#40036)
  removed a test due to random order generation
  Always restore when running a bootstrap build (dotnet#40025)
  fixed integration test capitalization for extract method and extract interface
  Fix tests pt2
  DiagnosticIncrementalAnalyzer refactoring (dotnet#39956)
  Persistence is always available in OOP
  Update src/Workspaces/Core/Portable/SolutionSize/SolutionSizeTracker.cs
  Fixed tests
  Move reporting of iterator diagnostics to avoid race condition (dotnet#39990)
  Update dependencies from https:/dotnet/arcade build 20191125.7 (dotnet#40020)
  Fix NGEN priority of csc.exe, vbc.exe, csi.exe (dotnet#40016)
  Accidentally deleted something
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment