Bug 20382 - mcs produces invalid code when library reference is missing
Summary: mcs produces invalid code when library reference is missing
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2014-06-05 12:11 UTC by Steffen Kieß
Modified: 2014-06-11 09:16 UTC (History)
1 user (show)

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 on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Steffen Kieß 2014-06-05 12:11:43 UTC
mcs produces invalid code when a library reference is missing in some cases (loading a field to an array of a generic struct which is in a missing library). Happens in 3.2.8 and on current master (92f13d1988c9bb23e59794ed40d1eaa37ec62098).

Steps to reproduce:
cat > GenericArrayMcsLib1.cs <<EOF
public struct Struct<T> {}
cat > GenericArrayMcsLib2.cs <<EOF
public class SomeClass {
  public Struct<int>[] ArrayMember;
cat > GenericArrayMcsProg.cs <<EOF
public static class Program {
  public static void Main () {
    var cls = new SomeClass ();
    var val = cls.ArrayMember; // Triggers TypeLoadException
    System.Console.WriteLine (val);
mcs -target:library GenericArrayMcsLib1.cs
mcs -target:library GenericArrayMcsLib2.cs -r:GenericArrayMcsLib1.dll
mcs -out:GenericArrayMcsProgWorking.exe GenericArrayMcsProg.cs -r:GenericArrayMcsLib1.dll -r:GenericArrayMcsLib2.dll
mcs -out:GenericArrayMcsProgBroken.exe GenericArrayMcsProg.cs -r:GenericArrayMcsLib2.dll
monodis GenericArrayMcsProgWorking.exe > GenericArrayMcsProgWorking.il
monodis GenericArrayMcsProgBroken.exe > GenericArrayMcsProgBroken.il
mono GenericArrayMcsProgWorking.exe
mono GenericArrayMcsProgBroken.exe

Actual results:
mono GenericArrayMcsProgBroken.exe
Unhandled Exception:
System.TypeLoadException: A type load exception has occurred.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.

diff -u GenericArrayMcsProgBroken.il GenericArrayMcsProgWorking.il
-		valuetype [GenericArrayMcsLib1]Struct`1<>[]	V_1)
+		valuetype [GenericArrayMcsLib1]Struct`1<int32>[]	V_1)

Expected behavior: Probably an error message when compiling GenericArrayMcsProgBroken.exe
Comment 1 Marek Safar 2014-06-11 09:16:46 UTC
Fixed in master