www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - AA bug..?

reply "Simen Haugen" <simen norstat.no> writes:
 int[uint] aa1 = [4290904102:1, 1:2]; // This works because 42909... is 
first

 int[uint] aa2 = [1:2, 4290904102:1]; // But here we get the error "cannot 
implicitly convert expression (4290904102L) of type long to int"

Is there something I'm missing, or is this a bug?
Sep 26 2007
parent reply "Vladimir Panteleev" <thecybershadow gmail.com> writes:
On Wed, 26 Sep 2007 15:49:46 +0300, Simen Haugen <simen norstat.no> wrot=
e:

  int[uint] aa1 =3D [4290904102:1, 1:2]; // This works because 42909...=
is
 first

  int[uint] aa2 =3D [1:2, 4290904102:1]; // But here we get the error "=
cannot
 implicitly convert expression (4290904102L) of type long to int"

 Is there something I'm missing, or is this a bug?
An AA literal's types are determined by the first elements. You can use = an explicit cast to set the literal's type: int[uint] aa2 =3D [cast(uint)1:2, 4290904102:1]; = -- = Best regards, Vladimir mailto:thecybershadow gmail.com
Sep 26 2007
next sibling parent reply "Simen Haugen" <simen norstat.no> writes:
I dont get it...

I say "int[uint]". Key is of type uint, value is of type int. What does it 
need to check the element types for?

"Vladimir Panteleev" <thecybershadow gmail.com> wrote in message 
news:op.ty9h4agxm02fvl irc.irastex.local...
On Wed, 26 Sep 2007 15:49:46 +0300, Simen Haugen <simen norstat.no> wrote:

  int[uint] aa1 = [4290904102:1, 1:2]; // This works because 42909... is
 first

  int[uint] aa2 = [1:2, 4290904102:1]; // But here we get the error "cannot
 implicitly convert expression (4290904102L) of type long to int"

 Is there something I'm missing, or is this a bug?
An AA literal's types are determined by the first elements. You can use an explicit cast to set the literal's type: int[uint] aa2 = [cast(uint)1:2, 4290904102:1]; -- Best regards, Vladimir mailto:thecybershadow gmail.com
Sep 26 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Simen Haugen" <simen norstat.no> wrote in message 
news:fddl53$2eai$1 digitalmars.com...
I dont get it...

 I say "int[uint]". Key is of type uint, value is of type int. What does it 
 need to check the element types for?
This != initializer. In this case the compiler doesn't even look at the type of the variable you're declaring. It's treating the initializer as if it were a literal. I wish the compiler _would_ see the type on the LHS, but..
Sep 26 2007
parent "Simen Haugen" <simen norstat.no> writes:
So its to get the init property to work.. The error message is certainly not 
very helpful, and this behaviour it is not documented.
Things like this should absolutly be documented as it's a bit hard to guess 
:)

Thanks for the help

"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message 
news:fddlil$2fct$1 digitalmars.com...
 "Simen Haugen" <simen norstat.no> wrote in message 
 news:fddl53$2eai$1 digitalmars.com...
I dont get it...

 I say "int[uint]". Key is of type uint, value is of type int. What does 
 it need to check the element types for?
This != initializer. In this case the compiler doesn't even look at the type of the variable you're declaring. It's treating the initializer as if it were a literal. I wish the compiler _would_ see the type on the LHS, but..
Sep 26 2007
prev sibling parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Vladimir Panteleev wrote:
 On Wed, 26 Sep 2007 15:49:46 +0300, Simen Haugen <simen norstat.no> wrote:
 
  int[uint] aa1 = [4290904102:1, 1:2]; // This works because 42909... is
 first

  int[uint] aa2 = [1:2, 4290904102:1]; // But here we get the error "cannot
 implicitly convert expression (4290904102L) of type long to int"

 Is there something I'm missing, or is this a bug?
An AA literal's types are determined by the first elements. You can use an explicit cast to set the literal's type: int[uint] aa2 = [cast(uint)1:2, 4290904102:1];
In this particular case, he can actually just use a suffix: int[uint] aa2 = [ 1_U : 2 , 4290904102_U : 1 ]; -- Chris Nicholson-Sauls
Sep 26 2007