Skip to content

Commit f55e3f7

Browse files
authored
Merge pull request #55769 from allisonchou/RevertRPSCherryPick2
Revert "Merge pull request #55738 from dotnet/main"
2 parents 8040dd3 + f8491a1 commit f55e3f7

File tree

106 files changed

+393
-3276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+393
-3276
lines changed

docs/features/ExpressionVariables.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ containing expression variables (out variable declarations and declaration patte
66
initializers, property initializers, ctor-initializers, and query clauses.
77

88
See https://github.com/dotnet/csharplang/issues/32 and
9-
https://github.com/dotnet/csharplang/blob/main/proposals/csharp-7.3/expression-variables-in-initializers.md
9+
https://github.com/dotnet/csharplang/blob/main/proposals/expression-variables-in-initializers.md
1010
for more information.
1111

1212
Current state of the feature:
1313

1414
[X] Permit in field initializers
1515
[X] Permit in property initializers
1616
[ ] Permit in ctor-initializers
17-
[X] Permit in query clauses
17+
[X] Permit in query clauses

dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"isRoot": true,
33
"tools": {
44
"dotnet-format": {
5-
"version": "6.0.240501",
5+
"version": "6.0.231801",
66
"commands": [
77
"dotnet-format"
88
]

eng/Versions.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
<RoslynDiagnosticsNugetPackageVersion>3.3.3-beta1.21105.3</RoslynDiagnosticsNugetPackageVersion>
3131
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-rc1.21366.2</MicrosoftCodeAnalysisNetAnalyzersVersion>
3232
<MicrosoftCodeAnalysisTestingVersion>1.1.0-beta1.21322.2</MicrosoftCodeAnalysisTestingVersion>
33-
<!-- CodeStyleAnalyzerVersion should we updated together with version of dotnet-format in dotnet-tools.json -->
34-
<CodeStyleAnalyzerVersion>4.0.0-3.final</CodeStyleAnalyzerVersion>
33+
<CodeStyleAnalyzerVersion>3.10.0</CodeStyleAnalyzerVersion>
3534
<VisualStudioEditorPackagesVersion>16.10.230</VisualStudioEditorPackagesVersion>
3635
<VisualStudioEditorNewPackagesVersion>17.0.278-preview</VisualStudioEditorNewPackagesVersion>
3736
<ILAsmPackageVersion>5.0.0-alpha1.19409.1</ILAsmPackageVersion>

src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ bool tryBindAsHandlerType([NotNullWhen(true)] out BoundInterpolatedString? resul
187187
{
188188
result = null;
189189

190-
if (InExpressionTree || !ValidateInterpolatedStringParts(unconvertedInterpolatedString))
190+
if (InExpressionTree || unconvertedInterpolatedString.Parts.ContainsAwaitExpression())
191191
{
192192
return false;
193193
}
@@ -204,12 +204,8 @@ bool tryBindAsHandlerType([NotNullWhen(true)] out BoundInterpolatedString? resul
204204
}
205205
}
206206

207-
private static bool ValidateInterpolatedStringParts(BoundUnconvertedInterpolatedString unconvertedInterpolatedString)
208-
=> !unconvertedInterpolatedString.Parts.ContainsAwaitExpression()
209-
&& unconvertedInterpolatedString.Parts.All(p => p is not BoundStringInsert { Value.Type.TypeKind: TypeKind.Dynamic });
210-
211207
private static bool AllInterpolatedStringPartsAreStrings(ImmutableArray<BoundExpression> parts)
212-
=> parts.All(p => p is BoundLiteral or BoundStringInsert { Value.Type.SpecialType: SpecialType.System_String, Alignment: null, Format: null });
208+
=> parts.All(p => p is BoundLiteral or BoundStringInsert { Value: { Type: { SpecialType: SpecialType.System_String } }, Alignment: null, Format: null });
213209

214210
private bool TryBindUnconvertedBinaryOperatorToDefaultInterpolatedStringHandler(BoundBinaryOperator binaryOperator, BindingDiagnosticBag diagnostics, [NotNullWhen(true)] out BoundBinaryOperator? convertedBinaryOperator)
215211
{
@@ -244,7 +240,7 @@ private bool TryBindUnconvertedBinaryOperatorToDefaultInterpolatedStringHandler(
244240
isConstant = isConstant && current.Right.ConstantValue is not null;
245241
var rightInterpolatedString = (BoundUnconvertedInterpolatedString)current.Right;
246242

247-
if (!ValidateInterpolatedStringParts(rightInterpolatedString))
243+
if (rightInterpolatedString.Parts.ContainsAwaitExpression())
248244
{
249245
// Exception to case 3. Delegate to standard binding.
250246
stack.Free();
@@ -263,7 +259,7 @@ private bool TryBindUnconvertedBinaryOperatorToDefaultInterpolatedStringHandler(
263259
case BoundUnconvertedInterpolatedString interpolatedString:
264260
isConstant = isConstant && interpolatedString.ConstantValue is not null;
265261

266-
if (!ValidateInterpolatedStringParts(interpolatedString))
262+
if (interpolatedString.Parts.ContainsAwaitExpression())
267263
{
268264
// Exception to case 3. Delegate to standard binding.
269265
stack.Free();

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,15 +1878,6 @@ internal void GenerateAnonymousFunctionConversionError(BindingDiagnosticBag diag
18781878
return;
18791879
}
18801880

1881-
if (reason == LambdaConversionResult.CannotInferDelegateType)
1882-
{
1883-
Debug.Assert(targetType.SpecialType == SpecialType.System_Delegate || targetType.IsNonGenericExpressionType());
1884-
Error(diagnostics, ErrorCode.ERR_CannotInferDelegateType, syntax);
1885-
var lambda = anonymousFunction.BindForErrorRecovery();
1886-
diagnostics.AddRange(lambda.Diagnostics);
1887-
return;
1888-
}
1889-
18901881
// At this point we know that we have either a delegate type or an expression type for the target.
18911882

18921883
// The target type is a valid delegate or expression tree type. Is there something wrong with the

src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System.Collections.Immutable;
88
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
910
using System.Threading;
1011
using Microsoft.CodeAnalysis.CSharp.Symbols;
1112
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -1393,8 +1394,7 @@ private static LambdaConversionResult IsAnonymousFunctionCompatibleWithExpressio
13931394

13941395
if (delegateType is null)
13951396
{
1396-
Debug.Assert(IsFeatureInferredDelegateTypeEnabled(anonymousFunction));
1397-
return GetInferredDelegateTypeResult(anonymousFunction);
1397+
return LambdaConversionResult.Success;
13981398
}
13991399

14001400
return IsAnonymousFunctionCompatibleWithDelegate(anonymousFunction, delegateType, isTargetExpressionTree: true);
@@ -1409,7 +1409,7 @@ public static LambdaConversionResult IsAnonymousFunctionCompatibleWithType(Unbou
14091409
{
14101410
if (IsFeatureInferredDelegateTypeEnabled(anonymousFunction))
14111411
{
1412-
return GetInferredDelegateTypeResult(anonymousFunction);
1412+
return LambdaConversionResult.Success;
14131413
}
14141414
}
14151415
else if (type.IsDelegateType())
@@ -1432,14 +1432,6 @@ internal static bool IsFeatureInferredDelegateTypeEnabled(BoundExpression expr)
14321432
return expr.Syntax.IsFeatureEnabled(MessageID.IDS_FeatureInferredDelegateType);
14331433
}
14341434

1435-
private static LambdaConversionResult GetInferredDelegateTypeResult(UnboundLambda anonymousFunction)
1436-
{
1437-
var discardedUseSiteInfo = CompoundUseSiteInfo<AssemblySymbol>.Discarded;
1438-
return anonymousFunction.InferDelegateType(ref discardedUseSiteInfo) is null ?
1439-
LambdaConversionResult.CannotInferDelegateType :
1440-
LambdaConversionResult.Success;
1441-
}
1442-
14431435
private static bool HasAnonymousFunctionConversion(BoundExpression source, TypeSymbol destination)
14441436
{
14451437
Debug.Assert(source != null);

src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/LambdaConversionResult.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ internal enum LambdaConversionResult
1616
StaticTypeInImplicitlyTypedLambda,
1717
ExpressionTreeMustHaveDelegateTypeArgument,
1818
ExpressionTreeFromAnonymousMethod,
19-
CannotInferDelegateType,
2019
BindingFailed
2120
}
2221
}

src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3650,7 +3650,7 @@ private void AddSynthesizedRecordMembersIfNecessary(MembersAndInitializersBuilde
36503650
memberNames.Free();
36513651

36523652
// Synthesizing non-readonly properties in struct would require changing readonly logic for PrintMembers method synthesis
3653-
Debug.Assert(isRecordClass || !members.Any(m => m is PropertySymbol { GetMethod.IsEffectivelyReadOnly: false }));
3653+
Debug.Assert(isRecordClass || !members.Any(m => m is PropertySymbol { GetMethod.IsEffectivelyReadOnly : false }));
36543654

36553655
// We put synthesized record members first so that errors about conflicts show up on user-defined members rather than all
36563656
// going to the record declaration

src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordCopyCtor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ internal override void GenerateMethodBodyStatements(SyntheticBoundNodeFactory F,
101101

102102
internal static bool IsCopyConstructor(Symbol member)
103103
{
104-
if (member is MethodSymbol { ContainingType.IsRecordStruct: false, MethodKind: MethodKind.Constructor } method)
104+
if (member is MethodSymbol { ContainingType: { IsRecordStruct: false }, MethodKind: MethodKind.Constructor } method)
105105
{
106106
return HasCopyConstructorSignature(method);
107107
}

src/Compilers/CSharp/Portable/Syntax/InternalSyntax/CSharpSyntaxNode.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#nullable disable
66

7-
using System;
87
using System.Collections.Generic;
98
using System.Diagnostics;
109
using System.Linq;
@@ -280,8 +279,8 @@ public override bool IsTriviaWithEndOfLine()
280279
}
281280

282281
// Use conditional weak table so we always return same identity for structured trivia
283-
private static readonly ConditionalWeakTable<SyntaxNode, Dictionary<CodeAnalysis.SyntaxTrivia, WeakReference<SyntaxNode>>> s_structuresTable
284-
= new ConditionalWeakTable<SyntaxNode, Dictionary<CodeAnalysis.SyntaxTrivia, WeakReference<SyntaxNode>>>();
282+
private static readonly ConditionalWeakTable<SyntaxNode, Dictionary<CodeAnalysis.SyntaxTrivia, SyntaxNode>> s_structuresTable
283+
= new ConditionalWeakTable<SyntaxNode, Dictionary<CodeAnalysis.SyntaxTrivia, SyntaxNode>>();
285284

286285
/// <summary>
287286
/// Gets the syntax node represented the structure of this trivia, if any. The HasStructure property can be used to
@@ -309,15 +308,10 @@ public override SyntaxNode GetStructure(Microsoft.CodeAnalysis.SyntaxTrivia triv
309308
var structsInParent = s_structuresTable.GetOrCreateValue(parent);
310309
lock (structsInParent)
311310
{
312-
if (!structsInParent.TryGetValue(trivia, out var weakStructure))
311+
if (!structsInParent.TryGetValue(trivia, out structure))
313312
{
314313
structure = CSharp.Syntax.StructuredTriviaSyntax.Create(trivia);
315-
structsInParent.Add(trivia, new WeakReference<SyntaxNode>(structure));
316-
}
317-
else if (!weakStructure.TryGetTarget(out structure))
318-
{
319-
structure = CSharp.Syntax.StructuredTriviaSyntax.Create(trivia);
320-
weakStructure.SetTarget(structure);
314+
structsInParent.Add(trivia, structure);
321315
}
322316
}
323317

0 commit comments

Comments
 (0)