boo-lang / boo

The Boo Programming Language.
BSD 3-Clause "New" or "Revised" License
874 stars 148 forks source link

Int values in literals within Attributes #137

Closed danijepg closed 8 years ago

danijepg commented 8 years ago

Compiling this code in Boo (note I'm ommitting the literal 'L' for long):

[FieldTrimAttribute(TrimMode.Both)]
[FieldNullValue (0)]
public NUMBER_OF_DAYS as int

Generates the following IL:

.custom instance void [FileHelpers]FileHelpers.FieldNullValueAttribute::.ctor(object) = ( 01 00 0A 03 00 00 00 00 00 00 00 00 00 )

While in C# 4.5 (similar code) generates:

.custom instance void [FileHelpers]FileHelpers.FieldNullValueAttribute::.ctor(object) = ( 01 00 08 03 00 00 00 00 00 )

As result, while compiling with Boo the attribute ctor receives a long and the c# compiled one receives an Int. This behaviour is pretty weird. Why is the 0 being interpreted as a long value by the compiler?

Is this a compiler bug in Boo, a design choice, or am I skipping something?

masonwheeler commented 8 years ago

This is definitely odd. A quick perusal of the relevant code makes it appear that this should be defaulting to int-type, and the attribute in question takes Object as its argument, so it's not being coerced to a Long.

I'll trace through this and see what's causing it when I get home.

masonwheeler commented 8 years ago

I found the problem. In EmitAssembly.GetValue, case NodeType.IntegerLiteralExpression, it will pull the value out of the IntegerLiteralExpression as a long rather than an int. I don't have time to fix this now, but I can check a fix in this evening if no one else codes it up first.

masonwheeler commented 8 years ago

Fixed.

danijepg commented 8 years ago

Thank you