Bug 31948 - Mono C# compiler incorrectly emits CS0647 for attributes on method parameters
Summary: Mono C# compiler incorrectly emits CS0647 for attributes on method parameters
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-07-14 16:09 UTC by emoriarty
Modified: 2015-07-21 05:11 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 emoriarty 2015-07-14 16:09:53 UTC
I encountered what appears to be a regression with using attributes on partial method parameters. The Mono C# compiler incorrectly emits CS0647 for attributes on method parameters as of 3.8.0, prior to that it did not. The current master (d07400cbd) still incorrectly emits the error. 

-----------------------------
$ cat Partial.cs
-----------------------------
using CustomAttributes;

partial class A
{
    // Partial methods w/o attributes.
    partial void PartialMethodWith_NoAttr_NoDefn(string s);
    partial void PartialMethodWith_NoAttr_Decl(string s);

    // Partial methods w/o a definition.
    [AttributeA("ANoDef")]
    partial void PartialMethodWith_AAttr_NoDefn(string s);
    partial void PartialMethodWith_BAttr_NoDefn([AttributeB("BNoDef")]string s);

    // Attributes only on declaration.
    [AttributeA("ADecl")]
    partial void PartialMethodWith_AAttr_Decl(string s);
    partial void PartialMethodWith_BAttr_Decl([AttributeB("BDecl")]string s); // Error CS0647

    // Attributes only on definition.
    partial void PartialMethodWith_AAttr_Defn(string s);
    partial void PartialMethodWith_BAttr_Defn(string s);

    // Different Attribute on definition.
    [AttributeA("WithABAttr")]
    partial void PartialMethodWith_ABAttr(string s);
    partial void PartialMethodWith_BAAttr([AttributeB("WithBAAttr")]string s); // Error CS0647
}

partial class A
{
    // Partial methods w/o attributes.
    partial void PartialMethodWith_NoAttr_Decl(string s) { }

    // Attributes only on declaration.
    partial void PartialMethodWith_AAttr_Decl(string s) { }
    partial void PartialMethodWith_BAttr_Decl(string s) { }

    // Attributes only on definition.
    [AttributeA("ADefn")]
    partial void PartialMethodWith_AAttr_Defn(string s) { }
    partial void PartialMethodWith_BAttr_Defn([AttributeB("BDefn")]string s) { }

    // Different Attribute on definition.
    [AttributeB("ABAttr")]
    partial void PartialMethodWith_ABAttr(string s) { }
    partial void PartialMethodWith_BAAttr([AttributeA("BAAttr")]string s) { }
}

----------------------------------------
$ cat CustomAttributes.cs 
----------------------------------------
using System;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace CustomAttributes {
    [AttributeUsage(AttributeTargets.All, AllowMultiple=true)]
    public class AttributeA : Attribute {
        public AttributeA(String a) {}
    }

    [AttributeUsage(AttributeTargets.All, AllowMultiple=true)]
    public class AttributeB : Attribute {
        public AttributeB(String a) {}
    }
}

------------------------------------------------
// Current Master (d07400cbd44) 
$ mcs /t:library Partial.cs CustomAttributes.cs 
------------------------------------------------
Partial.cs(17,48): error CS0647: Error during emitting `CustomAttributes.AttributeB' attribute. The reason is `Object reference not set to an instance of an object'
Partial.cs(26,44): error CS0647: Error during emitting `CustomAttributes.AttributeB' attribute. The reason is `Object reference not set to an instance of an object'
Compilation failed: 2 error(s), 0 warnings

---------------------------------------------------
// Visual Studio 2012 Development Console
$ csc /t:library Partial.cs CustomAttributes.cs
---------------------------------------------------
Microsoft (R) Visual C# Compiler version 12.0.21005.1
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.


----------------------------------------------------
Prior Versions
Using command line - 'mcs /t:library Partial.cs CustomAttribute.cs'
----------------------------------------------------
> mcs --version
Mono C# compiler version 3.0.7.0
[No errors]

> mcs --version
Mono C# compiler version 3.2.0.0
[No errors]

> mcs --version
Mono C# compiler version 3.2.8.0
[No errors]

> mcs --version
Mono C# compiler version 3.4.0.0
[No errors]

> mcs --version
Mono C# compiler version 3.6.0.0
[No errors]

> mcs --version
Mono C# compiler version 3.8.0.0
Partial.cs(17,48): error CS0647: Error during emitting `CustomAttributes.AttributeB' attribute. The reason is `Object reference not set to an instance of an object'
Partial.cs(26,44): error CS0647: Error during emitting `CustomAttributes.AttributeB' attribute. The reason is `Object reference not set to an instance of an object'
Compilation failed: 2 error(s), 0 warnings



Edward Moriarty | Software Engineer
Coverity | The Leader in Development Testing
Comment 1 Marek Safar 2015-07-21 05:11:21 UTC
Fixed in master and Mono 4.2