[nem-bug] [Nemerle 0000650]: Attribute compilation error.

feedback at nemerle.org feedback at nemerle.org
Sat Apr 8 18:40:57 CEST 2006


The following issue has been RESOLVED.
======================================================================
<http://nemerle.org/bugs/view.php?id=650> 
======================================================================
Reported By:                iae
Assigned To:                nazgul
======================================================================
Project:                    Nemerle
Issue ID:                   650
Category:                   Compiler
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     resolved
Resolution:                 fixed
Fixed in Version:           
======================================================================
Date Submitted:             04-07-2006 07:18 CEST
Last Modified:              04-08-2006 18:40 CEST
======================================================================
Summary:                    Attribute compilation error.
Description: 
I'm trying compile code:

	[Record]
	class MyAttr3Attribute : Attribute
	{
		[Accessor] mutable _s : string;
		[Accessor] mutable _i : int;
		[Accessor] mutable _c : char;
		[Accessor] mutable _m : decimal;
	}

	[MyAttr3("Name3", 3, 'c', 33.33m)]
	class TestMacroTest {}

But ncc throws exception:

       internal compiler error: got ArgumentException (An invalid type was
used as a custom attribute constructor argument, field or property.)
       at
System.Reflection.Emit.CustomAttributeBuilder.InitCustomAttributeBuilder(ConstructorInfo
con, Object[] constructorArgs, PropertyInfo[] namedProperties, Object[]
propertyValues, FieldInfo[] namedFields, Object[] fieldValues)
       at Nemerle.Compiler.AttributeCompiler.do_compile(GlobalEnv env,
TypeBuilder ti, TypeInfo attr, list`1 parms)
       at Nemerle.Compiler.AttributeCompiler.CompileAttribute(GlobalEnv
env, TypeBuilder ti, PExpr expr)
       at Nemerle.Compiler.Modifiers.SaveCustomAttributes(TypeBuilder ti,
Function`3 adder)
       at Nemerle.Compiler.TypeBuilder.EmitImplementation()
       at
Nemerle.Compiler.TypesManager._N_emit_impl_23354.apply_void(TypeBuilder
_N_23353)
       at
Nemerle.Compiler.TypesManager._N_maybe_f_23791.apply_void(TypeBuilder
_N_23790)
       at Nemerle.Collections.List.Iter['a](list`1 l, FunctionVoid`1 f)
       at Nemerle.Core.list`1.Iter(FunctionVoid`1 f)
       at Nemerle.Compiler.TypesManager.Iter(list`1 builders,
FunctionVoid`1 f)
       at Nemerle.Compiler.TypesManager.compile_all_tyinfos(Boolean
aux_phase)
       at Nemerle.Compiler.TypesManager._N__N_l22944_23028.apply_void()
       at Nemerle.Compiler.Solver.Enqueue(FunctionVoid action)
       at Nemerle.Compiler.Passes.Run()
       at Nemerle.CommandlineCompiler.MainClass.main_with_catching()
======================================================================

----------------------------------------------------------------------
 iae - 04-07-06 07:22 
----------------------------------------------------------------------
It seems that problem in method compile_expr for parameters of decimal
type.

----------------------------------------------------------------------
 nazgul - 04-07-06 14:12 
----------------------------------------------------------------------
This is most problably a bug in .NET runtime you are using. Is is MS.NET or
Mono? Which version?

----------------------------------------------------------------------
 iae - 04-07-06 14:46 
----------------------------------------------------------------------
I use MS fw.net 2.0. I just check similar code in C# and get an error: "An
attribute argument must be a constant expression, typeof expression or
array creation expression". So, I suppose this is bug of fw.net

----------------------------------------------------------------------
 iae - 04-07-06 20:16 
----------------------------------------------------------------------
Sorry guys, this was my fault. From C#2.0 specification:


24.1.3 Attribute parameter types 
The types of positional and named parameters for an attribute class are
limited to the attribute parameter types, which are: 
• One of the following types: bool, byte, char, double, float, int, long,
short, string. 
• The type object. 
• The type System.Type. 
• An enum type, provided it has public accessibility and the types in
which it is nested (if any) also have public accessibility. 
• Single-dimensional arrays of the above types.


So decimal cann't be Attribute parameter. Actually, this is not a C#
restriction, but .NET framework: it seems so decimal absent in metadata's
format.

But, I suggest generate more cleary error message then trivial exception.

----------------------------------------------------------------------
 nazgul - 04-08-06 11:40 
----------------------------------------------------------------------
Exactly, we should generate some clean error message here.

----------------------------------------------------------------------
 nazgul - 04-08-06 18:40 
----------------------------------------------------------------------
Fixed on trunk (r6177).
I've added the check.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
04-07-06 07:18 iae            New Issue                                    
04-07-06 07:22 iae            Note Added: 0001168                          
04-07-06 07:23 iae            Issue Monitored: iae                         
04-07-06 14:12 nazgul         Note Added: 0001169                          
04-07-06 14:46 iae            Note Added: 0001170                          
04-07-06 20:16 iae            Note Added: 0001171                          
04-08-06 11:40 nazgul         Note Added: 0001175                          
04-08-06 18:40 nazgul         Status                   new => resolved     
04-08-06 18:40 nazgul         Resolution               open => fixed       
04-08-06 18:40 nazgul         Assigned To               => nazgul          
04-08-06 18:40 nazgul         Note Added: 0001177                          
======================================================================




More information about the bugs mailing list