Create default arguments during binding#49186
Conversation
This comment has been minimized.
This comment has been minimized.
c4ad664 to
b6cd75a
Compare
b6cd75a to
fe03afe
Compare
fe03afe to
29e0d7a
Compare
src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Outdated
Show resolved
Hide resolved
|
Thanks for the feedback @333fred. |
| { | ||
| case BoundKind.PropertyGroup: | ||
| expr = BindIndexedPropertyAccess((BoundPropertyGroup)expr, mustHaveAllOptionalParameters: false, diagnostics: diagnostics); | ||
| expr = BindIndexerDefaultArguments(expr, valueKind, diagnostics); |
There was a problem hiding this comment.
BindIndexerDefaultArguments [](start = 27, length = 27)
Does this have any effect?
There was a problem hiding this comment.
Yes. In some scenarios, we can call an indexer whose parameters are all optional by omitting the element access syntax entirely. Here's a test that demonstrates this:
| if (useSetAccessor) | ||
| { | ||
| parameters = parameters.RemoveAt(parameters.Length - 1); | ||
| Debug.Assert(parameters.Length == indexerAccess.Indexer.Parameters.Length); |
There was a problem hiding this comment.
Debug.Assert [](start = 20, length = 12)
Consider moving assert after if so it's executed always.
src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs
Outdated
Show resolved
Hide resolved
| { | ||
| // This is only expected to occur in recursive error scenarios, for example: `object F(object param = F()) { }` | ||
| // We return a non-error expression here to ensure ERR_DefaultValueMustBeConstant (or another appropriate diagnostics) is produced by the caller. | ||
| return new BoundDefaultExpression(syntax, parameterType) { WasCompilerGenerated = true }; |
There was a problem hiding this comment.
I think this could technically change observable behavior for nullability warnings or IOperation results, but I think that's fine.
There was a problem hiding this comment.
If we decide to start giving nullability warnings for default arguments then we might want to add a nullable suppression to this node, but we'll cross that bridge if we come to it
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArgument.cs
Outdated
Show resolved
Hide resolved
333fred
left a comment
There was a problem hiding this comment.
Done review pass (commit 4). Just a couple of minor comments left.
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_UsingStatement.cs
Show resolved
Hide resolved
| // that never expires, then the failure mode will be to spin wait forever. | ||
| // For debug purposes let's instead use a token which expires after a modest amount of time | ||
| // to wait for the default syntax value to be available. | ||
| var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); |
There was a problem hiding this comment.
We need to pick a much higher number here. It is more than reasonable for a thread to hang for 5 secnds in CI
There was a problem hiding this comment.
Looks like integration tests use 1 minute to wait for things to complete in some places. I'll go with that as a starting point
| #else | ||
| var token = CancellationToken.None; | ||
| #endif | ||
| state.SpinWaitComplete(CompletionPart.EndDefaultSyntaxValue, token); |
There was a problem hiding this comment.
Feel like ForceComplete should change to assert that this part has completed. That is the pattern we usually have elsewhere.
There was a problem hiding this comment.
I didn't find examples of asserting that parts are completed instead of spin-waiting for them to complete when looking through the overrides of Symbol.ForceComplete. Could you provide an example of what you had in mind?
* upstream/master: (148 commits) Remove unnecessary ArrayBuilder in MakeCallWithNoExplicitArgument (dotnet#49377) Revert "Skip binary for determinism checking" Use deterministic metadata names for emitted anonymous type fields. (dotnet#49370) Reuse LSP solutions if they don't need re-forking (dotnet#49305) Small nullability fixes (dotnet#49279) Create default arguments during binding (dotnet#49186) Clean nits Backport dotnet#48420 to release/dev16.8 (dotnet#49357) Rewrite AnalyzeFileReference.GetSupportedLanguages without LINQ (dotnet#49337) Use .Any extension of ImmutableArray(Of Symbol) (dotnet#48980) fix 'remove unnecessary cast' when doing bitwise ops on unsigned values. Harden, document, cross-link XunitDisposeHook Simplify x86 hook Fix split comment exporting for VB. Code style fix Overwrite xunit's app domain handling to not call AppDomain.Unload Revert pragma suppression Remove blank line Revert file Move block structure code back to Features layer ...
| BoundExpression defaultValue; | ||
| if (callerSourceLocation is object && parameter.IsCallerLineNumber) | ||
| { | ||
| int line = GetCallerLocation(syntax).SourceTree.GetDisplayLineNumber(callerSourceLocation.SourceSpan); |
There was a problem hiding this comment.
Should use callerSourceLocation here instead of GetCallerLocation here
* Restore default argument binding behavior to be like it was before dotnet#49186, only asserting that parameters are optional, rather than checking. Prior code steps should have verified this. * Don't bind default arguments for error cases. * Add additional tests.
Closes #17243
Closes #47352
This PR has been organized to try and improve reviewability.