Bug 28976 - "using static" not consulted for libraries
Summary: "using static" not consulted for libraries
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
: 30755 ()
Depends on:
Blocks:
 
Reported: 2015-04-10 09:02 UTC by Malcolm Rowe
Modified: 2015-06-04 10:49 UTC (History)
2 users (show)

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

Description Malcolm Rowe 2015-04-10 09:02:18 UTC
In mono-4.0.0, C#6-style "using static" statements do not appear to be consulted if the type is in another assembly.

-- Constants.cs
public static class Constants
{
  public const long One = 1;
}
-- Program.cs
using static Constants;

static class Program
{
  static void Main(string[] args)
  {
    System.Console.WriteLine(One);
  }
}
--

With mono-4.0.0-branch 9236ac4, I get the following:

$ mcs Program.cs Constants.cs
$ mono Program.exe
1
$

However:

$ mcs -target:library Constants.cs -out:Constants.dll
$ mcs Program.cs -r:Constants
Program.cs(7,30): error CS0103: The name `One' does not exist in the current context
Compilation failed: 1 error(s), 0 warnings
$

(monop shows that the contents of Constants.dll is as expected, and if you replace the Console.WriteLine call with "WriteLine(Constants.One)", it works as expected.)
Comment 1 Malcolm Rowe 2015-04-10 09:58:19 UTC
This also fails in master/4fc75b3.
Comment 2 Marek Safar 2015-04-13 08:20:21 UTC
Fixed in master
Comment 3 Malcolm Rowe 2015-04-13 08:59:30 UTC
Thanks for the quick fix. b526af0 applies cleanly to mono-4.0.0-branch too; it'd be great if the fix could be backported.
Comment 4 Marek Safar 2015-06-04 10:49:50 UTC
*** Bug 30755 has been marked as a duplicate of this bug. ***