diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSubstitutedTypeParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSubstitutedTypeParameterSymbol.cs index fc8221d9ad1f4..56979139e7487 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSubstitutedTypeParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSubstitutedTypeParameterSymbol.cs @@ -5,6 +5,7 @@ #nullable disable using System.Collections.Immutable; +using System.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Emit; using Microsoft.CodeAnalysis.PooledObjects; @@ -18,6 +19,10 @@ internal sealed class SynthesizedSubstitutedTypeParameterSymbol : SubstitutedTyp public SynthesizedSubstitutedTypeParameterSymbol(Symbol owner, TypeMap map, TypeParameterSymbol substitutedFrom, int ordinal) : base(owner, map, substitutedFrom, ordinal) { + Debug.Assert(this.TypeParameterKind == (ContainingSymbol is MethodSymbol ? TypeParameterKind.Method : + (ContainingSymbol is NamedTypeSymbol ? TypeParameterKind.Type : + TypeParameterKind.Cref)), + $"Container is {ContainingSymbol?.Kind}, TypeParameterKind is {this.TypeParameterKind}"); } public override bool IsImplicitlyDeclared @@ -25,6 +30,8 @@ public override bool IsImplicitlyDeclared get { return true; } } + public override TypeParameterKind TypeParameterKind => ContainingSymbol is MethodSymbol ? TypeParameterKind.Method : TypeParameterKind.Type; + internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder attributes) { base.AddSynthesizedAttributes(moduleBuilder, ref attributes); diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedClonedTypeParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedClonedTypeParameterSymbol.vb index 85122d83b1244..d7a9a545059da 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedClonedTypeParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedClonedTypeParameterSymbol.vb @@ -45,6 +45,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols _correspondingMethodTypeParameter = correspondingMethodTypeParameter _name = name _typeMapFactory = typeMapFactory + + Debug.Assert(Me.TypeParameterKind = If(TypeOf Me.ContainingSymbol Is MethodSymbol, TypeParameterKind.Method, + If(TypeOf Me.ContainingSymbol Is NamedTypeSymbol, TypeParameterKind.Type, + TypeParameterKind.Cref)), + $"Container is {Me.ContainingSymbol?.Kind}, TypeParameterKind is {Me.TypeParameterKind}") End Sub Public Overrides ReadOnly Property TypeParameterKind As TypeParameterKind diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedTypeParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedTypeParameterSymbol.vb index c9cc775bfcd3d..a98e82937f542 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedTypeParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedTypeParameterSymbol.vb @@ -88,6 +88,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Public Sub New(underlyingTypeParameter As TypeParameterSymbol) Debug.Assert(underlyingTypeParameter IsNot Nothing) Me._underlyingTypeParameter = underlyingTypeParameter + + Debug.Assert(Me.TypeParameterKind = If(TypeOf Me.ContainingSymbol Is MethodSymbol, TypeParameterKind.Method, + If(TypeOf Me.ContainingSymbol Is NamedTypeSymbol, TypeParameterKind.Type, + TypeParameterKind.Cref)), + $"Container is {Me.ContainingSymbol?.Kind}, TypeParameterKind is {Me.TypeParameterKind}") End Sub Public Overrides Function GetDocumentationCommentXml(Optional preferredCulture As CultureInfo = Nothing, Optional expandIncludes As Boolean = False, Optional cancellationToken As CancellationToken = Nothing) As String diff --git a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/SimpleTypeParameterSymbol.cs b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/SimpleTypeParameterSymbol.cs index de45ef9551757..604bfbce2c7b8 100644 --- a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/SimpleTypeParameterSymbol.cs +++ b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/SimpleTypeParameterSymbol.cs @@ -8,6 +8,7 @@ using Roslyn.Utilities; using System; using System.Collections.Immutable; +using System.Diagnostics; namespace Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator { @@ -25,6 +26,11 @@ public SimpleTypeParameterSymbol(Symbol container, int ordinal, string name) _container = container; _ordinal = ordinal; _name = name; + + Debug.Assert(this.TypeParameterKind == (ContainingSymbol is MethodSymbol ? TypeParameterKind.Method : + (ContainingSymbol is NamedTypeSymbol ? TypeParameterKind.Type : + TypeParameterKind.Cref)), + $"Container is {ContainingSymbol?.Kind}, TypeParameterKind is {this.TypeParameterKind}"); } public override string Name @@ -39,7 +45,7 @@ public override int Ordinal public override TypeParameterKind TypeParameterKind { - get { return TypeParameterKind.Type; } + get { return ContainingSymbol is MethodSymbol ? TypeParameterKind.Method : TypeParameterKind.Type; } } public override bool HasConstructorConstraint diff --git a/src/ExpressionEvaluator/VisualBasic/Source/ExpressionCompiler/Symbols/SimpleTypeParameterSymbol.vb b/src/ExpressionEvaluator/VisualBasic/Source/ExpressionCompiler/Symbols/SimpleTypeParameterSymbol.vb index 6ac0b20075f3a..19b822a4c7a74 100644 --- a/src/ExpressionEvaluator/VisualBasic/Source/ExpressionCompiler/Symbols/SimpleTypeParameterSymbol.vb +++ b/src/ExpressionEvaluator/VisualBasic/Source/ExpressionCompiler/Symbols/SimpleTypeParameterSymbol.vb @@ -21,6 +21,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator _container = container _ordinal = ordinal _name = name + + Debug.Assert(Me.TypeParameterKind = If(TypeOf Me.ContainingSymbol Is MethodSymbol, TypeParameterKind.Method, + If(TypeOf Me.ContainingSymbol Is NamedTypeSymbol, TypeParameterKind.Type, + TypeParameterKind.Cref)), + $"Container is {Me.ContainingSymbol?.Kind}, TypeParameterKind is {Me.TypeParameterKind}") End Sub Public Overrides ReadOnly Property Name As String @@ -37,7 +42,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator Public Overrides ReadOnly Property TypeParameterKind As TypeParameterKind Get - Return TypeParameterKind.Type + Return If(TypeOf Me.ContainingSymbol Is MethodSymbol, TypeParameterKind.Method, TypeParameterKind.Type) End Get End Property