Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[generator] Fix an NRE when cloning a method with generic arguments. #1089

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/generator-Tests/Unit-Tests/GenBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ public void TestEqualsMethodsWithOneParameter ()
Assert.False (c.RequiresNew (m.Name, m));
}

[Test]
public void TestMethodClone_GenericArguments ()
{
var c = SupportTypeBuilder.CreateClass ("java.myClass", options);
var m = SupportTypeBuilder.CreateMethod (c, "DoStuff", options);

m.GenericArguments = new GenericParameterDefinitionList {
new GenericParameterDefinition ("T", null)
};

var clone = m.Clone (c);

Assert.AreEqual (1, clone.GenericArguments.Count);
Assert.AreEqual ("T", clone.GenericArguments [0].Name);
}

void TestParameterlessMethods (string name)
{
var c = SupportTypeBuilder.CreateClass ("java.myClass", options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ public Method Clone (GenBase declaringType)
clone.SourceFile = SourceFile;
clone.JavadocInfo = JavadocInfo;

if (GenericArguments != null)
if (GenericArguments != null) {
if (clone.GenericArguments is null)
clone.GenericArguments = new GenericParameterDefinitionList ();

foreach (var ga in GenericArguments)
clone.GenericArguments.Add (ga.Clone ());
}

foreach (var p in Parameters)
clone.Parameters.Add (p.Clone ());
Expand Down