Bug 35269

Summary: CS0208 which appears or disappears based on filename ordering on command-line.
Product: [Mono] Compilers Reporter: Jonathan Pryor <jonp>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 4.0.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: bxc-35269.zip

Description Jonathan Pryor 2015-10-26 15:18:30 UTC
C# is (normally) an order-independent language, in that it doesn't matter what order you declare types within a file, or what order you provide files on the command-line, or what order you reference assemblies.
Comment 1 Jonathan Pryor 2015-10-26 15:20:47 UTC
Created attachment 13532 [details]
bxc-35269.zip

Test case
Comment 2 Jonathan Pryor 2015-10-26 15:31:13 UTC
Behold! A counter example appears.

Attachment #13532 [details] contains an example wherein changing the order of filenames on the command-line results in success or failure on compiler output:

> $  make works
> mcs /unsafe /t:library /out:works.dll JavaObject.cs JniObjectReference.cs JniReferenceSafeHandle.cs
> JniObjectReference.cs(7,27): warning CS0169: The private field `Java.Interop.JniObjectReference.safeHandle' is never used
> Compilation succeeded - 1 warning(s)

> $ make fails
> mcs /unsafe /t:library /out:fails.dll JniObjectReference.cs JavaObject.cs JniReferenceSafeHandle.cs
> JavaObject.cs(7,35): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type `Java.Interop.JniObjectReference'
> JniObjectReference.cs(5,16): (Location of the symbol related to previous error)
> Compilation failed: 1 error(s), 0 warnings

The difference between the two lines is the relationship between JniObjectReference.cs and JavaObject.cs: if JniObjectReference.cs comes *first*, it fails to compile. If it comes *after*, it succeeds.

Which, mind you, is extremely confusing and I think is the *opposite* of where I first saw this appear!

> $ mcs --version
> Mono C# compiler version 4.0.4.0

Actual behavior: Compiler error or no error depending on the ordering of filenames.

Expected behavior: The compiler should at least be consistent! :-)

Also, the code should fail to compile:

> CSC /unsafe JavaObject.cs JniObjectReference.cs JniReferenceSafeHandle.cs
> Microsoft (R) Visual C# Compiler version 4.0.30319.34209 for Microsoft (R) .NET Framework 4.5
> Copyright (C) Microsoft Corporation. All rights reserved.
> 
> JavaObject.cs(7,59): error CS0208: Cannot take the address of, get the size of,
>         or declare a pointer to a managed type
>         ('Java.Interop.JniObjectReference')
> JniObjectReference.cs(5,16): (Location of symbol related to previous error)
Comment 3 Marek Safar 2015-10-27 05:21:38 UTC
Fixed in master/6262c487d38ce3575ebe8f6425e63dfceb3adf96