Skip to content

[generator] Fix exception caused by incorrect nested type name. #1267

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

Merged
merged 1 commit into from
Oct 21, 2024
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
24 changes: 24 additions & 0 deletions tests/generator-Tests/Unit-Tests/ManagedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public void UnknownTypes (object unknown) { }

[Register ("com/mypackage/service")]
public interface IService { }

[Register ("com/mypackage/FieldClass")]
public class FieldClass : Java.Lang.Object
{
public NestedFieldClass field;

public class NestedFieldClass : Java.Lang.Object { }
}

}

namespace GenericTestClasses
Expand Down Expand Up @@ -133,6 +142,21 @@ public void Class ()
Assert.IsNull (@class.DeprecatedComment);
}

[Test]
public void FieldWithNestedType ()
{
var @class = CecilApiImporter.CreateClass (module.GetType ("Com.Mypackage.FieldClass"), options);
var @class2 = CecilApiImporter.CreateClass (module.GetType ("Com.Mypackage.FieldClass/NestedFieldClass"), options);

options.SymbolTable.AddType (@class);
options.SymbolTable.AddType (@class2);

Assert.IsTrue (@class.Validate (options, new GenericParameterDefinitionList (), new CodeGeneratorContext ()), "@class.Validate failed!");

// Ensure the front slash is replaced with a period
Assert.AreEqual ("Com.Mypackage.FieldClass.NestedFieldClass", @class.Fields [0].TypeName);
}

[Test]
public void Method ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public static Field CreateField (FieldDefinition f)
Visibility = f.IsPublic ? "public" : f.IsFamilyOrAssembly ? "protected internal" : f.IsFamily ? "protected" : f.IsAssembly ? "internal" : "private"
};

field.SetterParameter = CreateParameter (f.FieldType.Resolve ()?.FullName ?? f.FieldType.FullName, null);
var field_parameter_type = f.FieldType.Resolve () ?? f.FieldType;
field.SetterParameter = CreateParameter (field_parameter_type.FullNameCorrected ().StripArity (), null);
field.SetterParameter.Name = "value";

return field;
Expand Down