Bug 20382

Summary: mcs produces invalid code when library reference is missing
Product: [Mono] Compilers Reporter: Steffen Kieß <Steffen.Kiess>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

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> {}
EOF
cat > GenericArrayMcsLib2.cs <<EOF
public class SomeClass {
  public Struct<int>[] ArrayMember;
}
EOF
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);
  }
}
EOF
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