Bug 52489 - ilasm fails with "Circular definition of class" for Generic Singleton<T> designs
Summary: ilasm fails with "Circular definition of class" for Generic Singleton<T> designs
Status: NEW
Alias: None
Product: Compilers
Classification: Mono
Component: IL assembler ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
: 8745 ()
Depends on:
Blocks:
 
Reported: 2017-02-14 03:25 UTC by pushedx
Modified: 2018-01-10 02:11 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 52489 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description pushedx 2017-02-14 03:25:23 UTC
[Overview]

This bug had been previously filed on the Novell bugtracker a long time ago, but has not been fixed or migrated to this bugtracker since: https://bugzilla.novell.com/show_bug.cgi?id=443159

I added a few extra key words to the Summary for search visibility, as the Singleton pattern is just one example of where this bug happens in practice when round-tripping mono assemblies.

[Steps to Reproduce]

-- Program.cs --

namespace bug_report_generic_self
{
	public class Singleton<T> { }

	public class TestClass : Singleton<TestClass> { }

	class Program
	{
		static void Main(string[] args)
		{
			var obj = new TestClass();
		}
	}
}

-- Example disasm generation (note: I used msvc to compile the exe for simplicity) --

ikdasm.exe bug_report_generic_self.exe /OUT=bug_report_generic_self.il /COMPAT=2.0

https://gist.github.com/anonymous/2a6bff220314efcadf90afa7143a398c

-- Example (mono) ilasm generation

ilasm.exe /exe /output:bug_report_generic_self_ilasm.exe bug_report_generic_self.il

	Assembling 'bug_report_generic_self.il' , no listing file, to exe --> 'bug_report_generic_self_ilasm.exe'

	bug_report_generic_self.il : Error : Circular definition of class: bug_report_generic_self.TestClass

	***** FAILURE *****

[Expected Results]

For this code scenario to be handled correctly like .Net's ilasm does.

[Additional Information]

I cloned mono master earlier today, because I needed some other fixes in ilasm that are not in Releases, and followed the "http://www.mono-project.com/docs/compiling-mono/windows" guide to get all this setup.

$ git log -1
commit 9433d2c80a59f54cb43452adfe49a9c2a3a674d1
Author: <removed>
Date:   Mon Feb 13 09:56:11 2017 -0500

    Bump bockbuild

Just including that information for completeness though, as the issue has been around for so long it's not specific to anything new.

I really would like to implement a solution for this myself, but I don't understand what actually needs to be done to solve the circular definition lookup. I tried adding in a parent-less type definition, resolved the parent, remove the parent-less type definition, and continue, but that didn't work because I'd also need to modify PEAPI as well to remove the temp definition, and then re-fix the referenced type. That seemed a bit convoluted, so I was hoping there'd be a better way.
Comment 1 Alexander Köplinger [MSFT] 2018-01-10 02:11:08 UTC
Given the age of the issue it probably won't show up on our radar anytime soon so a community fix would be greatly appreciated :)

I'd reach out to the mono-devel mailing list for questions (https://lists.dot.net/mailman/listinfo/mono-devel-list).
Comment 2 Alexander Köplinger [MSFT] 2018-01-10 02:11:14 UTC
*** Bug 8745 has been marked as a duplicate of this bug. ***