Bug 318663 (MONO75723) - [PATCH] CS0182 reported on valid attributes
Summary: [PATCH] CS0182 reported on valid attributes
Status: RESOLVED FIXED
Alias: MONO75723
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-05 12:53 UTC by Guillaume Comeau
Modified: 2007-09-15 21:24 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
proposed corlib fix (686 bytes, patch)
2005-08-24 19:28 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:26:43 UTC


---- Reported by gcomeau@hotmail.com 2005-08-05 05:53:35 MST ----

Getting error CS0182: An attribute argument must be a constant expression,
typeof expression or array creation expression
on near trivial sample of code that goes through csc just fine. 


Code sample:
using System;


// The attribute
internal class MyAttr : Attribute {
  internal MyAttr() { }
  internal MyAttr(Type type) { }
  internal MyAttr(string name) { }
  internal MyAttr(int i) { }
}

// The Classes
[MyAttr()]
internal class ClassA  { }

[MyAttr(typeof(string))]
internal class ClassB  { }

[MyAttr("abc")]
internal class ClassC  { }

[MyAttr(3)]
internal class ClassD  { }

// Just to compile
internal class Top  { 
  public static void Main (string[] strgs){}
}


Result: 
$ mcs classes.cs
classes.cs(21) error CS0182: An attribute argument must be a constant
expression
, typeof expression or array creation expression
classes.cs(24) error CS0182: An attribute argument must be a constant
expression
, typeof expression or array creation expression
classes.cs(27) error CS0182: An attribute argument must be a constant
expression
, typeof expression or array creation expression
classes.cs(30) error CS0182: An attribute argument must be a constant
expression
, typeof expression or array creation expression
Compilation failed: 4 error(s), 0 warnings



Expected Results: Should compile

How often does this happen: Always.



---- Additional Comments From atsushi@ximian.com 2005-08-24 12:28:01 MST ----

Created an attachment (id=168318)
proposed corlib fix




---- Additional Comments From atsushi@ximian.com 2005-08-24 12:32:00 MST ----

In Attribute.Resolve (file attribute.cs), mcs catches all kind of
exceptions i.e. catch (Exception) that hides ArgumentException raised
in CustomAttributeBuilder.ctor().

Maybe we should remove that try-catch.




---- Additional Comments From rharinath@novell.com 2005-10-03 03:00:16 MST ----

Looks good.

As for the try-catch around CustomAttributeBuilder -- we need that
since the .NET SRE appears to be incomplete.  I think we probably
should print the caught exception with 'mcs -v'.




---- Additional Comments From atsushi@ximian.com 2005-10-03 06:20:24 MST ----

Applied the patch (r51110).

Imported an attachment (id=168318)

Unknown operating system unknown. Setting to default OS "Other".