Skip to content

Commit a723b92

Browse files
author
msftbot[bot]
authored
Merge pull request #45413 from dotnet/merges/master-to-master-vs-deps
Merge master to master-vs-deps
2 parents 1462b1e + 25cc3f3 commit a723b92

File tree

17 files changed

+541
-88
lines changed

17 files changed

+541
-88
lines changed

docs/features/source-generators.cookbook.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ MyGenerator.props:
509509
<Project>
510510
<ItemGroup>
511511
<CompilerVisibleProperty Include="MyGenerator_EnableLogging" />
512-
<CompilerVisibleMetadata Include="AdditionalFiles" MetadataName="MyGenerator_EnableLogging" />
512+
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="MyGenerator_EnableLogging" />
513513
</ItemGroup>
514514
</Project>
515515
```

src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseImplicitTypeTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,5 +2735,35 @@ static void Main(string[] args)
27352735
}",
27362736
options: ImplicitTypeEverywhere());
27372737
}
2738+
2739+
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUseExplicitType)]
2740+
[WorkItem(44507, "https://github.com/dotnet/roslyn/issues/44507")]
2741+
public async Task DoNotSuggestVarInAmbiguousSwitchExpression()
2742+
{
2743+
await TestMissingAsync(
2744+
@"using System;
2745+
2746+
class C
2747+
{
2748+
void M()
2749+
{
2750+
var i = 1;
2751+
[||]C x = i switch
2752+
{
2753+
0 => new A(),
2754+
1 => new B(),
2755+
_ => throw new ArgumentException(),
2756+
};
2757+
}
2758+
}
2759+
2760+
class A : C
2761+
{
2762+
}
2763+
2764+
class B : C
2765+
{
2766+
}", parameters: new TestParameters(options: ImplicitTypeEverywhere()));
2767+
}
27382768
}
27392769
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ private BoundExpression BindWithExpression(WithExpressionSyntax syntax, Diagnost
4949
diagnose: false,
5050
ref useSiteDiagnostics);
5151

52-
// https://github.com/dotnet/roslyn/issues/44908 - Should handle hiding/overriding
5352
if (lookupResult.IsMultiViable)
5453
{
5554
foreach (var symbol in lookupResult.Symbols)

src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,8 +1949,6 @@ protected void EnsureNullabilityAnalysisPerformedIfNecessary()
19491949

19501950
upgradeableLock.EnterWrite();
19511951

1952-
Debug.Assert(Root == bindableRoot);
1953-
19541952
NullableWalker.SnapshotManager snapshotManager;
19551953
var remappedSymbols = _parentRemappedSymbolsOpt;
19561954
BoundNode boundRoot;
@@ -1977,10 +1975,10 @@ protected void EnsureNullabilityAnalysisPerformedIfNecessary()
19771975
rewriteAndCache();
19781976
}
19791977

1980-
void bind(CSharpSyntaxNode bindableRoot, out Binder binder, out BoundNode boundRoot)
1978+
void bind(CSharpSyntaxNode root, out Binder binder, out BoundNode boundRoot)
19811979
{
1982-
binder = GetEnclosingBinder(GetAdjustedNodePosition(bindableRoot));
1983-
boundRoot = Bind(binder, bindableRoot, getDiagnosticBag());
1980+
binder = GetEnclosingBinder(GetAdjustedNodePosition(root));
1981+
boundRoot = Bind(binder, root, getDiagnosticBag());
19841982
}
19851983

19861984
void rewriteAndCache()
@@ -2145,20 +2143,27 @@ internal protected virtual CSharpSyntaxNode GetBindableSyntaxNode(CSharpSyntaxNo
21452143

21462144
while (true)
21472145
{
2148-
switch (node.Kind())
2146+
switch (node)
21492147
{
2150-
case SyntaxKind.ParenthesizedExpression:
2151-
node = ((ParenthesizedExpressionSyntax)node).Expression;
2148+
case ParenthesizedExpressionSyntax n:
2149+
node = n.Expression;
21522150
continue;
21532151

2154-
case SyntaxKind.CheckedExpression:
2155-
case SyntaxKind.UncheckedExpression:
2156-
node = ((CheckedExpressionSyntax)node).Expression;
2152+
case CheckedExpressionSyntax n:
2153+
node = n.Expression;
21572154
continue;
21582155

21592156
// Simple mitigation to give a result for suppressions. Public API tracked by https://github.com/dotnet/roslyn/issues/26198
2160-
case SyntaxKind.SuppressNullableWarningExpression:
2161-
node = ((PostfixUnaryExpressionSyntax)node).Operand;
2157+
case PostfixUnaryExpressionSyntax { RawKind: (int)SyntaxKind.SuppressNullableWarningExpression } n:
2158+
node = n.Operand;
2159+
continue;
2160+
2161+
case UnsafeStatementSyntax n:
2162+
node = n.Block;
2163+
continue;
2164+
2165+
case CheckedStatementSyntax n:
2166+
node = n.Block;
21622167
continue;
21632168
}
21642169

src/Compilers/CSharp/Test/Semantic/FlowAnalysis/RegionAnalysisTests.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System;
66
using System.Linq;
7-
using Microsoft.CodeAnalysis.CSharp.Symbols;
87
using Microsoft.CodeAnalysis.CSharp.Syntax;
98
using Microsoft.CodeAnalysis.Test.Extensions;
109
using Roslyn.Test.Utilities;
@@ -4162,6 +4161,56 @@ static void Main(string[] args)
41624161
Assert.Null(GetSymbolNamesJoined(dataFlowAnalysisResults.VariablesDeclared));
41634162
}
41644163

4164+
[Fact]
4165+
[WorkItem(4950, "https://github.com/dotnet/roslyn/issues/4950")]
4166+
public void RegionWithUnsafeBlock()
4167+
{
4168+
var source =
4169+
@"using System;
4170+
class Program {
4171+
static void Main(string[] args) {
4172+
object value = args;
4173+
4174+
// start
4175+
IntPtr p;
4176+
unsafe
4177+
{
4178+
object t = value;
4179+
p = IntPtr.Zero;
4180+
}
4181+
// end
4182+
4183+
Console.WriteLine(p);
4184+
}
4185+
}
4186+
";
4187+
foreach (string keyword in new[] { "unsafe", "checked", "unchecked" })
4188+
{
4189+
var compilation = CreateCompilation(source.Replace("unsafe", keyword));
4190+
var tree = compilation.SyntaxTrees[0];
4191+
var model = compilation.GetSemanticModel(tree);
4192+
4193+
var stmt1 = tree.GetCompilationUnitRoot().DescendantNodesAndSelf().OfType<StatementSyntax>().Where(n => n.ToString() == "IntPtr p;").Single();
4194+
var stmt2 = tree.GetCompilationUnitRoot().DescendantNodesAndSelf().OfType<StatementSyntax>().Where(n => n.ToString().StartsWith(keyword)).First();
4195+
4196+
var dataFlowAnalysisResults = model.AnalyzeDataFlow(stmt1, stmt2);
4197+
Assert.True(dataFlowAnalysisResults.Succeeded);
4198+
Assert.Equal("p, t", GetSymbolNamesJoined(dataFlowAnalysisResults.VariablesDeclared));
4199+
Assert.Equal("p, t", GetSymbolNamesJoined(dataFlowAnalysisResults.AlwaysAssigned));
4200+
Assert.Null(GetSymbolNamesJoined(dataFlowAnalysisResults.Captured));
4201+
Assert.Null(GetSymbolNamesJoined(dataFlowAnalysisResults.CapturedInside));
4202+
Assert.Null(GetSymbolNamesJoined(dataFlowAnalysisResults.CapturedOutside));
4203+
Assert.Equal("value", GetSymbolNamesJoined(dataFlowAnalysisResults.DataFlowsIn));
4204+
Assert.Equal("p", GetSymbolNamesJoined(dataFlowAnalysisResults.DataFlowsOut));
4205+
Assert.Equal("args, value", GetSymbolNamesJoined(dataFlowAnalysisResults.DefinitelyAssignedOnEntry));
4206+
Assert.Equal("args, value, p, t", GetSymbolNamesJoined(dataFlowAnalysisResults.DefinitelyAssignedOnExit));
4207+
Assert.Equal("value", GetSymbolNamesJoined(dataFlowAnalysisResults.ReadInside));
4208+
Assert.Equal("args, p", GetSymbolNamesJoined(dataFlowAnalysisResults.ReadOutside));
4209+
Assert.Equal("p, t", GetSymbolNamesJoined(dataFlowAnalysisResults.WrittenInside));
4210+
Assert.Equal("args, value", GetSymbolNamesJoined(dataFlowAnalysisResults.WrittenOutside));
4211+
}
4212+
}
4213+
41654214
#endregion
41664215

41674216
#region "lambda"

src/Compilers/CSharp/Test/Semantic/Semantics/OperatorTests.cs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,130 @@ static void M(int a, int b, int c, int d, int e, int f, int g, int h, int i)
25502550
VerifyOperationTreeAndDiagnosticsForTest<BlockSyntax>(source, expectedOperationTree, expectedDiagnostics);
25512551
}
25522552

2553+
[CompilerTrait(CompilerFeature.IOperation)]
2554+
[Fact]
2555+
public void TestCompoundAssignment_Unchecked_IOperation()
2556+
{
2557+
string source = @"
2558+
class C
2559+
{
2560+
static void M(int a, int b, int c, int d, int e, int f, int g, int h, int i)
2561+
/*<bind>*/{
2562+
unchecked
2563+
{
2564+
a += b;
2565+
a -= c;
2566+
a *= d;
2567+
a /= e;
2568+
a %= f;
2569+
a <<= 10;
2570+
a >>= 20;
2571+
a &= g;
2572+
a |= h;
2573+
a ^= i;
2574+
}
2575+
}/*</bind>*/
2576+
}
2577+
";
2578+
string expectedOperationTree = @"
2579+
IBlockOperation (1 statements) (OperationKind.Block, Type: null) (Syntax: '{ ... }')
2580+
IBlockOperation (10 statements) (OperationKind.Block, Type: null) (Syntax: '{ ... }')
2581+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a += b;')
2582+
Expression:
2583+
ICompoundAssignmentOperation (BinaryOperatorKind.Add) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a += b')
2584+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2585+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2586+
Left:
2587+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2588+
Right:
2589+
IParameterReferenceOperation: b (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'b')
2590+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a -= c;')
2591+
Expression:
2592+
ICompoundAssignmentOperation (BinaryOperatorKind.Subtract) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a -= c')
2593+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2594+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2595+
Left:
2596+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2597+
Right:
2598+
IParameterReferenceOperation: c (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'c')
2599+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a *= d;')
2600+
Expression:
2601+
ICompoundAssignmentOperation (BinaryOperatorKind.Multiply) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a *= d')
2602+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2603+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2604+
Left:
2605+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2606+
Right:
2607+
IParameterReferenceOperation: d (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'd')
2608+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a /= e;')
2609+
Expression:
2610+
ICompoundAssignmentOperation (BinaryOperatorKind.Divide) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a /= e')
2611+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2612+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2613+
Left:
2614+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2615+
Right:
2616+
IParameterReferenceOperation: e (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'e')
2617+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a %= f;')
2618+
Expression:
2619+
ICompoundAssignmentOperation (BinaryOperatorKind.Remainder) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a %= f')
2620+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2621+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2622+
Left:
2623+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2624+
Right:
2625+
IParameterReferenceOperation: f (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'f')
2626+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a <<= 10;')
2627+
Expression:
2628+
ICompoundAssignmentOperation (BinaryOperatorKind.LeftShift) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a <<= 10')
2629+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2630+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2631+
Left:
2632+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2633+
Right:
2634+
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 10) (Syntax: '10')
2635+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a >>= 20;')
2636+
Expression:
2637+
ICompoundAssignmentOperation (BinaryOperatorKind.RightShift) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a >>= 20')
2638+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2639+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2640+
Left:
2641+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2642+
Right:
2643+
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 20) (Syntax: '20')
2644+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a &= g;')
2645+
Expression:
2646+
ICompoundAssignmentOperation (BinaryOperatorKind.And) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a &= g')
2647+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2648+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2649+
Left:
2650+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2651+
Right:
2652+
IParameterReferenceOperation: g (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'g')
2653+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a |= h;')
2654+
Expression:
2655+
ICompoundAssignmentOperation (BinaryOperatorKind.Or) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a |= h')
2656+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2657+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2658+
Left:
2659+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2660+
Right:
2661+
IParameterReferenceOperation: h (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'h')
2662+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'a ^= i;')
2663+
Expression:
2664+
ICompoundAssignmentOperation (BinaryOperatorKind.ExclusiveOr) (OperationKind.CompoundAssignment, Type: System.Int32) (Syntax: 'a ^= i')
2665+
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2666+
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
2667+
Left:
2668+
IParameterReferenceOperation: a (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'a')
2669+
Right:
2670+
IParameterReferenceOperation: i (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'i')
2671+
";
2672+
var expectedDiagnostics = DiagnosticDescription.None;
2673+
2674+
VerifyOperationTreeAndDiagnosticsForTest<BlockSyntax>(source, expectedOperationTree, expectedDiagnostics);
2675+
}
2676+
25532677
[Fact]
25542678
public void TestUserDefinedBinaryOperatorOverloadResolution()
25552679
{

src/Compilers/CSharp/Test/Semantic/Semantics/UnsafeTests.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,31 @@ class C
216216
{
217217
void Goo()
218218
{
219-
unsafe { }
219+
/*<bind>*/unsafe
220+
{
221+
_ = 0;
222+
}/*</bind>*/
220223
}
221224
}
222225
";
223226

224-
CreateCompilation(text, options: TestOptions.UnsafeReleaseDll.WithAllowUnsafe(false)).VerifyDiagnostics(
225-
// (6,9): error CS0227: Unsafe code may only appear if compiling with /unsafe
226-
Diagnostic(ErrorCode.ERR_IllegalUnsafe, "unsafe"));
227+
string expectedOperationTree = @"
228+
IBlockOperation (1 statements) (OperationKind.Block, Type: null) (Syntax: '{ ... }')
229+
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: '_ = 0;')
230+
Expression:
231+
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Int32) (Syntax: '_ = 0')
232+
Left:
233+
IDiscardOperation (Symbol: System.Int32 _) (OperationKind.Discard, Type: System.Int32) (Syntax: '_')
234+
Right:
235+
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 0) (Syntax: '0')
236+
";
237+
VerifyOperationTreeAndDiagnosticsForTest<BlockSyntax>(text, expectedOperationTree,
238+
compilationOptions: TestOptions.UnsafeReleaseDll.WithAllowUnsafe(false),
239+
expectedDiagnostics: new DiagnosticDescription[] {
240+
// file.cs(6,19): error CS0227: Unsafe code may only appear if compiling with /unsafe
241+
// /*<bind>*/unsafe
242+
Diagnostic(ErrorCode.ERR_IllegalUnsafe, "unsafe").WithLocation(6, 19)
243+
});
227244

228245
CreateCompilation(text, options: TestOptions.UnsafeReleaseDll).VerifyDiagnostics();
229246
}

0 commit comments

Comments
 (0)