Skip to content

Commit

Permalink
Calculate TypeParameterKind based on the container type (#54200)
Browse files Browse the repository at this point in the history
Fixes #54104.
  • Loading branch information
MykolaBalakin authored Jun 25, 2021
1 parent c1ec4b3 commit 0130339
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable disable

using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;

Expand All @@ -18,13 +19,19 @@ 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
{
get { return true; }
}

public override TypeParameterKind TypeParameterKind => ContainingSymbol is MethodSymbol ? TypeParameterKind.Method : TypeParameterKind.Type;

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedAttributes(moduleBuilder, ref attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Roslyn.Utilities;
using System;
using System.Collections.Immutable;
using System.Diagnostics;

namespace Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator
{
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 0130339

Please sign in to comment.