Skip to content

Commit 704a5e4

Browse files
committed
Revert "C#: Avoid NPE in Parameter.Populate"
This reverts commit 08eb7e2.
1 parent 8ccbcf1 commit 704a5e4

File tree

1 file changed

+11
-7
lines changed
  • csharp/extractor/Semmle.Extraction.CSharp/Entities

1 file changed

+11
-7
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ namespace Semmle.Extraction.CSharp.Entities
1010
{
1111
internal class Parameter : CachedSymbol<IParameterSymbol>, IExpressionParentEntity
1212
{
13-
protected IEntity Parent { get; set; }
13+
protected IEntity? Parent { get; set; }
1414
protected Parameter Original { get; }
1515

1616
protected Parameter(Context cx, IParameterSymbol init, IEntity? parent, Parameter? original)
1717
: base(cx, init)
1818
{
19-
Parent = parent
20-
?? Method.Create(Context, Symbol.ContainingSymbol as IMethodSymbol)
21-
?? throw new InternalError(Symbol, "Couldn't get parent of symbol.");
19+
Parent = parent;
2220
Original = original ?? this;
2321
}
2422

@@ -65,6 +63,12 @@ public static Parameter Create(Context cx, IParameterSymbol param) =>
6563

6664
public override void WriteId(EscapingTextWriter trapFile)
6765
{
66+
if (Parent is null)
67+
Parent = Method.Create(Context, Symbol.ContainingSymbol as IMethodSymbol);
68+
69+
if (Parent is null)
70+
throw new InternalError(Symbol, "Couldn't get parent of symbol.");
71+
6872
trapFile.WriteSubId(Parent);
6973
trapFile.Write('_');
7074
trapFile.Write(Ordinal);
@@ -95,7 +99,7 @@ public override void Populate(TextWriter trapFile)
9599
Context.ModelError(Symbol, "Inconsistent parameter declaration");
96100

97101
var type = Type.Create(Context, Symbol.Type);
98-
trapFile.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent, Original);
102+
trapFile.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent!, Original);
99103

100104
foreach (var l in Symbol.Locations)
101105
trapFile.param_location(this, Context.CreateLocation(l));
@@ -228,11 +232,11 @@ public override void Populate(TextWriter trapFile)
228232
{
229233
var typeKey = VarargsType.Create(Context);
230234
// !! Maybe originaldefinition is wrong
231-
trapFile.@params(this, "", typeKey, Ordinal, Kind.None, Parent, this);
235+
trapFile.@params(this, "", typeKey, Ordinal, Kind.None, Parent!, this);
232236
trapFile.param_location(this, GeneratedLocation.Create(Context));
233237
}
234238

235-
protected override int Ordinal => ((Method)Parent).OriginalDefinition.Symbol.Parameters.Length;
239+
protected override int Ordinal => ((Method)Parent!).OriginalDefinition.Symbol.Parameters.Length;
236240

237241
public override int GetHashCode()
238242
{

0 commit comments

Comments
 (0)