Bug 35269 - CS0208 which appears or disappears based on filename ordering on command-line.
Summary: CS0208 which appears or disappears based on filename ordering on command-line.
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 4.0.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-10-26 15:18 UTC by Jonathan Pryor
Modified: 2015-10-27 05:21 UTC (History)
1 user (show)

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


Attachments
bxc-35269.zip (1.33 KB, application/zip)
2015-10-26 15:20 UTC, Jonathan Pryor
Details


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:
Status:
RESOLVED FIXED

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