Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 01, 2004 Possible type-system bug | ||||
---|---|---|---|---|
| ||||
I'm not sure that the following really is a bug, but i definitly think so. The code below does not compile. ------------------ int main() { int a = 2; int[5] b; int[] c = new int[b[a]]; return 0; } ---------------- t.d(5): need size of rightmost array, not type [a]b But if i insert some paranthesis around the b[a] argument i give for the allocation size of c, it compiles perfectly. ---------------- int main() { int a = 2; int[5] b; int[] c = new int[(b[a])]; return 0; } It seemse like the D-typechecker dosen't evaluate b[a] to an int in the first case, perhaps that's completly correct, but i can't see why... /Robin |
March 01, 2004 Re: Possible type-system bug | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robin Håkanson | Hmm, it seems the ( ) solve many problems ( bugs? ) , like the opCall() for the Streams Mik was working on. Just in time for 1.0 :D. C On Mon, 1 Mar 2004 18:21:17 +0000 (UTC), Robin Håkanson <Robin_member@pathlink.com> wrote: > I'm not sure that the following really is a bug, but i definitly think so. > > The code below does not compile. > ------------------ > int main() > { > int a = 2; > int[5] b; > int[] c = new int[b[a]]; > > return 0; > } > ---------------- > t.d(5): need size of rightmost array, not type [a]b > > > But if i insert some paranthesis around the b[a] argument i give for the > allocation size of c, it compiles perfectly. > ---------------- > int main() > { > int a = 2; > int[5] b; > int[] c = new int[(b[a])]; > > return 0; > } > > > > It seemse like the D-typechecker dosen't evaluate b[a] to an int in the first > case, perhaps that's completly correct, but i can't see why... > > /Robin > > -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
March 01, 2004 Re: Possible type-system bug | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robin Håkanson | Definitely looks like a bug. In parse.c the parsing of "new" looks like it confuses int[b[a]] with an associative array - possibly by thinking it was parsing a declaration in parseBasicType2... I can't really tell. You can replace "b[a]" with any expression like 0+b[a] or b[a]+0 or as you found (b[a]) and it'll get out the the jam. -Ben |
March 02, 2004 Re: Possible type-system bug | ||||
---|---|---|---|---|
| ||||
Posted in reply to C | Can't the compiler know in this case that b (thus b[2]) is uninitialized, and be rejecting the "new int[really=0]" as undefined? Then when parens wrap it the compiler knows it will have a value (type int)... Well, the message is a bit strange, but is probably trying to say "type member of array of ints", whereas the () wrapper will force evaluation to some int value. Convoluted?
<snip>
>> The code below does not compile.
>> ------------------
>> int main()
>> {
>> int a = 2;
>> int[5] b;
>> int[] c = new int[b[a]]; // ok if b[a] is wrapped as (b[a])
>
>>
>> return 0;
>> }
>> ----------------
>> t.d(5): need size of rightmost array, not type [a]b
>>
</snip>
|
Copyright © 1999-2021 by the D Language Foundation