Skip to content

Commit be807aa

Browse files
authored
Do not use a constructed method symbol in a BoundMethodDefIndex (#79211)
1 parent 5ff6dc1 commit be807aa

File tree

9 files changed

+308
-3
lines changed

9 files changed

+308
-3
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Diagnostics;
6+
7+
namespace Microsoft.CodeAnalysis.CSharp
8+
{
9+
internal partial class BoundMethodDefIndex
10+
{
11+
private partial void Validate()
12+
{
13+
Debug.Assert(Method.IsDefinition);
14+
}
15+
}
16+
}

src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@
739739

740740
<!-- Represents the raw metadata RowId value for a method definition.
741741
Used by dynamic instrumentation to index into tables or arrays of per-method information. -->
742-
<Node Name="BoundMethodDefIndex" Base="BoundExpression">
742+
<Node Name="BoundMethodDefIndex" Base="BoundExpression" HasValidate="true">
743743
<!-- Non-null type is required for this node kind -->
744744
<Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow"/>
745745
<Field Name="Method" Type="MethodSymbol"/>

src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/Lowering/BoundTreeToDifferentEnclosingContextRewriter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ public override BoundNode VisitAwaitableValuePlaceholder(BoundAwaitableValuePlac
188188
;
189189
}
190190

191+
public override BoundNode? VisitMethodDefIndex(BoundMethodDefIndex node)
192+
{
193+
// Cannot replace a MethodDefIndex's Method/Type with a substituted symbol.
194+
Debug.Assert(node.Type.Equals(VisitType(node.Type), TypeCompareKind.ConsiderEverything));
195+
return node;
196+
}
197+
191198
[return: NotNullIfNotNull(nameof(method))]
192199
public override MethodSymbol? VisitMethodSymbol(MethodSymbol? method)
193200
{

src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs

Lines changed: 254 additions & 0 deletions
Large diffs are not rendered by default.

src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicAnalysisResourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.CodeAnalysis.CSharp.DynamicAnalysis.UnitTests
2020
{
2121
public class DynamicAnalysisResourceTests : CSharpTestBase
2222
{
23-
const string InstrumentationHelperSource = @"
23+
public const string InstrumentationHelperSource = @"
2424
namespace Microsoft.CodeAnalysis.Runtime
2525
{
2626
public static class Instrumentation
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
' Licensed to the .NET Foundation under one or more agreements.
2+
' The .NET Foundation licenses this file to you under the MIT license.
3+
' See the LICENSE file in the project root for more information.
4+
5+
Imports Microsoft.CodeAnalysis.Text
6+
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
7+
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
8+
9+
Namespace Microsoft.CodeAnalysis.VisualBasic
10+
Partial Friend Class BoundMethodDefIndex
11+
#If DEBUG Then
12+
Private Sub Validate()
13+
Debug.Assert(Method.IsDefinition)
14+
End Sub
15+
#End If
16+
End Class
17+
End Namespace

src/Compilers/VisualBasic/Portable/BoundTree/BoundNodes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256

257257
<!-- Represents the raw metadata token index value for a method definition.
258258
Used by dynamic instrumentation to index into tables or arrays of per-method information. -->
259-
<Node Name="BoundMethodDefIndex" Base="BoundExpression">
259+
<Node Name="BoundMethodDefIndex" Base="BoundExpression" HasValidate="true">
260260
<!-- Non-null type is required for this node kind -->
261261
<Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow"/>
262262
<Field Name="Method" Type="MethodSymbol"/>

src/Compilers/VisualBasic/Portable/Generated/BoundNodes.xml.Generated.vb

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)