diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs b/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs
index 496b57400..4fc9185c8 100644
--- a/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs
+++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using generator.SourceWriters;
using MonoDroid.Generation;
using NUnit.Framework;
using Xamarin.Android.Binder;
+using Xamarin.SourceWriter;
namespace generatortests
{
@@ -1271,5 +1273,55 @@ public void WriteClassInternalBase ()
Assert.True (result.Contains ("internal static new IntPtr class_ref".NormalizeLineEndings ()));
Assert.False (result.Contains ("internal static IntPtr class_ref".NormalizeLineEndings ()));
}
+
+ [Test]
+ public void WriteBoundMethodAbstractDeclarationWithGenericReturn ()
+ {
+ // Fix a case where the ReturnType of a class method implementing a generic interface method
+ // that has a generic parameter type return (like T) wasn't getting set, resulting in a NRE.
+ var gens = ParseApiDefinition (@"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ");
+
+ var declIface = gens.OfType ().Single (c => c.Name == "IFlowIterator");
+ var declClass = declIface.NestedTypes.OfType ().Single (c => c.Name == "FlowIteratorRangeIterator");
+ var method = declClass.Methods.Single ();
+
+ var bmad = new BoundMethodAbstractDeclaration (declClass, method, options, null);
+ var source_writer = new CodeWriter (writer);
+
+ bmad.Write (source_writer);
+
+ var expected = @"Java.Lang.Object Com.Example.FlowIteratorRangeIterator.Next ()
+ {
+ throw new NotImplementedException ();
+ }";
+
+ // Ignore nullable operator so this test works on all generators ;)
+ Assert.AreEqual (expected.NormalizeLineEndings (), writer.ToString ().NormalizeLineEndings ().Replace ("?", ""));
+ }
}
}
diff --git a/tools/generator/SourceWriters/BoundMethodAbstractDeclaration.cs b/tools/generator/SourceWriters/BoundMethodAbstractDeclaration.cs
index cf6ab032b..a2fbf0f0e 100644
--- a/tools/generator/SourceWriters/BoundMethodAbstractDeclaration.cs
+++ b/tools/generator/SourceWriters/BoundMethodAbstractDeclaration.cs
@@ -19,6 +19,9 @@ public BoundMethodAbstractDeclaration (GenBase gen, Method method, CodeGeneratio
this.method = method;
this.opt = opt;
+ ReturnType = new TypeReferenceWriter (opt.GetTypeReferenceName (method.RetVal));
+ this.AddMethodParameters (method.Parameters, opt);
+
if (method.RetVal.IsGeneric && gen != null) {
Name = method.Name;
ExplicitInterfaceImplementation = opt.GetOutputName (gen.FullName);
@@ -35,7 +38,6 @@ public BoundMethodAbstractDeclaration (GenBase gen, Method method, CodeGeneratio
IsAbstract = true;
IsShadow = impl.RequiresNew (method.Name, method);
SetVisibility (method.Visibility);
- ReturnType = new TypeReferenceWriter (opt.GetTypeReferenceName (method.RetVal));
NewFirst = true;
@@ -51,7 +53,6 @@ public BoundMethodAbstractDeclaration (GenBase gen, Method method, CodeGeneratio
Attributes.Add (new RegisterAttr (method.JavaName, method.JniSignature, method.ConnectorName, additionalProperties: method.AdditionalAttributeString ()));
SourceWriterExtensions.AddMethodCustomAttributes (Attributes, method);
- this.AddMethodParameters (method.Parameters, opt);
}
public override void Write (CodeWriter writer)