Bug 31948

Summary: Mono C# compiler incorrectly emits CS0647 for attributes on method parameters
Product: [Mono] Compilers Reporter: emoriarty
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
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:

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