Bug 24675

Summary: Mono C# parser encounters a CS0584 internal compiler error when loading a constant from a legal dll
Product: [Mono] Compilers Reporter: emoriarty
Component: C#Assignee: Marek Safar <masafa>
Severity: normal CC: mono-bugs+mono, sig-rnd-sat-mono-bugs
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: B.dll

Description emoriarty 2014-11-19 14:11:39 UTC
Created attachment 8808 [details]

When trying to compile a program using a dll that csc and ILDASM/ILASM consider valid the mono C# compiler encounters an internal compiler error.

The problem appears to be that in the dll's IL representation it is assigning an int16 value to a unit16 static literal and mono does not like this. I do not have access to the original source for the dll and was unable to determine what kind of source or compilation is required to generate the IL that mono errors out on.

using TypeLib;
public class Bar
      public const int FIELD = Foo.CONSTANT;

B.il - IL for the attached B.dll
//  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.1
//  Copyright (c) Microsoft Corporation.  All rights reserved.
// Metadata version: v2.0.50727
.assembly extern mscorlib
  .ver 2:0:0:0
.assembly TypeLib
  .hash algorithm 0x00008004
  .ver 1:0:0:0
.class public abstract auto ansi TypeLib.Foo
       extends [mscorlib]System.Object
  // Mono doesn't like int16 here
  // If I change it to uint16 the error goes away.
  .field public static literal uint16 CONSTANT = int16(0xFFFF) 

Command Lines - See attached for copy of B.dll
$ /opt/pkg/mono-3.8.0/bin/mcs /t:library /r:B.dll Reproducer.cs
Reproducer.cs(4,36): error CS0584: Internal compiler error: Unexpected error when loading type `TypeLib.Foo'
error CS0133: The expression being assigned to `Bar.FIELD' must be constant
Compilation failed: 2 error(s), 0 warnings

$ csc /t:library /r:B.dll Reproducer.cs
Microsoft (R) Visual C# Compiler version 4.0.30319.18408
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.

Edward Moriarty | Junior Engineer
Coverity | The Leader in Development Testing
Comment 1 Marek Safar 2015-02-06 11:55:13 UTC
Fixed in master