digitalmars.D.learn - Three legitimate bugs? (D1.061)
- strtr (59/59) May 15 2010 Should I report these bugs?
- bearophile (7/9) May 15 2010 Something simple like:
- strtr (5/14) May 15 2010 As it is really time consuming to construct test cases out of large proj...
- Steven Schveighoffer (15/36) May 17 2010 Unlike some languages, D1 const does not imply static. Which means you ...
- strtr (2/38) May 17 2010 But why would uncommenting S1 result in compilable code?
- Steven Schveighoffer (4/42) May 17 2010 Hm... that's a good question. I guess my belief is wrong. And that wou...
- bearophile (12/15) May 17 2010 It seems the const implies static, in structs... I don't know if this is...
- Steven Schveighoffer (5/20) May 17 2010 No, I was simply wrong :) I think it's by design. Which means the
- bearophile (16/18) May 17 2010 The original bug report is valid, but I don't understand that code still...
- Don (5/30) May 18 2010 In D1, the two are totally different. The second one is the only
- Don (3/35) May 18 2010 D'oh, should read the title. This was a D1 question. Yes it's
- bearophile (6/8) May 18 2010 Sorry, I have added more confusion.
- Stewart Gordon (20/23) May 29 2010 It's implying static in this context according to my testing. Try this
- Stewart Gordon (20/49) May 29 2010 The general answer to this question is: Yes, as long as
Should I report these bugs? (and how should I call this first one?) ---- module main; //const S S1 = S(); // uncomment this to compile struct S { float value; static S opCall() { S s; return s; } const S S2 = S(); } void main(){} -- main.d(4): Error: struct main.S no size yet for forward reference main.d(4): Error: struct main.S no size yet for forward reference main.d(11): Error: cannot evaluate opCall() at compile time ---- ---- module main; import t_def; class C{ mixin T!(); } void main(){ C c = new C(); c.func(); } -- module t_def; template T() { int[] arr; public void func() { arr[1] = 42; } } -- run main.exe Error: ArrayBoundsError main.d(8) should be t_def.d(8) ---- ---- module main; const S S1 = S(); struct S { static S func( S s_ ) out(result){ assert(false,random); } body{ return s_; } const S S2 = func(S()); } void main(){} -- main.d(11): Error: cannot evaluate func((S())) at compile time ----
May 15 2010
strtr Wrote:Should I report these bugs?Yes, add them to bugzilla. The third one is especially cute.(and how should I call this first one?)Something simple like: Forward reference error with struct opCall and const Let's see how much time it takes to reach 5000 bugs :-) Bye, bearophile
May 15 2010
== Quote from bearophile (bearophileHUGS lycos.com)'s articlestrtr Wrote:Was kind of expecting you to correct me or point me to the corresponding bugzillas ;DShould I report these bugs?Yes, add them to bugzilla. The third one is especially cute.As it is really time consuming to construct test cases out of large projects, lets hope a while ;) Although I do like the search..(and how should I call this first one?)Something simple like: Forward reference error with struct opCall and const Let's see how much time it takes to reach 5000 bugs :-) Bye, bearophile
May 15 2010
On Sat, 15 May 2010 16:15:23 -0400, strtr <strtr spam.com> wrote:Should I report these bugs? (and how should I call this first one?) ---- module main; //const S S1 = S(); // uncomment this to compile struct S { float value; static S opCall() { S s; return s; } const S S2 = S(); } void main(){} -- main.d(4): Error: struct main.S no size yet for forward reference main.d(4): Error: struct main.S no size yet for forward reference main.d(11): Error: cannot evaluate opCall() at compile time ----Unlike some languages, D1 const does not imply static. Which means you are trying to define an S as containing an S, which would then contain another S and so on. This should work: struct S { float value; static S opCall() { S s; return s; } static const S S2 = S(); } -Steve
May 17 2010
== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleOn Sat, 15 May 2010 16:15:23 -0400, strtr <strtr spam.com> wrote:But why would uncommenting S1 result in compilable code?Should I report these bugs? (and how should I call this first one?) ---- module main; //const S S1 = S(); // uncomment this to compile struct S { float value; static S opCall() { S s; return s; } const S S2 = S(); } void main(){} -- main.d(4): Error: struct main.S no size yet for forward reference main.d(4): Error: struct main.S no size yet for forward reference main.d(11): Error: cannot evaluate opCall() at compile time ----Unlike some languages, D1 const does not imply static. Which means you are trying to define an S as containing an S, which would then contain another S and so on. This should work: struct S { float value; static S opCall() { S s; return s; } static const S S2 = S(); } -Steve
May 17 2010
On Mon, 17 May 2010 10:28:47 -0400, strtr <strtr spam.com> wrote:== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleHm... that's a good question. I guess my belief is wrong. And that would imply that my code doesn't compile... -SteveOn Sat, 15 May 2010 16:15:23 -0400, strtr <strtr spam.com> wrote:But why would uncommenting S1 result in compilable code?Should I report these bugs? (and how should I call this first one?) ---- module main; //const S S1 = S(); // uncomment this to compile struct S { float value; static S opCall() { S s; return s; } const S S2 = S(); } void main(){} -- main.d(4): Error: struct main.S no size yet for forward reference main.d(4): Error: struct main.S no size yet for forward reference main.d(11): Error: cannot evaluate opCall() at compile time ----Unlike some languages, D1 const does not imply static. Which means you are trying to define an S as containing an S, which would then contain another S and so on. This should work: struct S { float value; static S opCall() { S s; return s; } static const S S2 = S(); } -Steve
May 17 2010
Steven Schveighoffer:Unlike some languages, D1 const does not imply static. Which means you are trying to define an S as containing an S, which would then contain another S and so on.It seems the const implies static, in structs... I don't know if this is by design, or it's a compiler bug, or something. I don't understand. This doesn't asserts: struct Foo { float value; const Foo f = Foo(); } void main() { assert(Foo.sizeof == 4); } This looks like a compiler bug that I can add it to bugzilla. Bye, bearophile
May 17 2010
On Mon, 17 May 2010 15:31:23 -0400, bearophile <bearophileHUGS lycos.com> wrote:Steven Schveighoffer:No, I was simply wrong :) I think it's by design. Which means the original bug report is valid. -SteveUnlike some languages, D1 const does not imply static. Which means you are trying to define an S as containing an S, which would then contain another S and so on.It seems the const implies static, in structs... I don't know if this is by design, or it's a compiler bug, or something. I don't understand. This doesn't asserts: struct Foo { float value; const Foo f = Foo(); } void main() { assert(Foo.sizeof == 4); } This looks like a compiler bug that I can add it to bugzilla.
May 17 2010
Steven Schveighoffer:No, I was simply wrong :) I think it's by design. Which means the original bug report is valid.The original bug report is valid, but I don't understand that code still. Is the const implying a static only in some situations? Why is this OK for the compiler: struct Foo { const Foo f = Foo(); } static assert(Foo.sizeof == 1); void main() {} While this is not OK for the compiler? struct Foo { const Foo f; } static assert(Foo.sizeof == 1); void main() {} Bye, bearophile
May 17 2010
bearophile wrote:Steven Schveighoffer:In D1, the two are totally different. The second one is the only situation in D1 where 'const' doesn't mean compile-time constant. I guess the same behaviour has been applied in D2, but I'm not sure if that's intentional or not.No, I was simply wrong :) I think it's by design. Which means the original bug report is valid.The original bug report is valid, but I don't understand that code still. Is the const implying a static only in some situations? Why is this OK for the compiler: struct Foo { const Foo f = Foo(); } static assert(Foo.sizeof == 1); void main() {} While this is not OK for the compiler? struct Foo { const Foo f; } static assert(Foo.sizeof == 1); void main() {} Bye, bearophile
May 18 2010
Don wrote:bearophile wrote:D'oh, should read the title. This was a D1 question. Yes it's intentional, and yes it's confusing.Steven Schveighoffer:In D1, the two are totally different. The second one is the only situation in D1 where 'const' doesn't mean compile-time constant. I guess the same behaviour has been applied in D2, but I'm not sure if that's intentional or not.No, I was simply wrong :) I think it's by design. Which means the original bug report is valid.The original bug report is valid, but I don't understand that code still. Is the const implying a static only in some situations? Why is this OK for the compiler: struct Foo { const Foo f = Foo(); } static assert(Foo.sizeof == 1); void main() {} While this is not OK for the compiler? struct Foo { const Foo f; } static assert(Foo.sizeof == 1); void main() {} Bye, bearophile
May 18 2010
Don:D'oh, should read the title. This was a D1 question. Yes it's intentional, and yes it's confusing.Sorry, I have added more confusion. I have added this, but I have used DMD2: http://d.puremagic.com/issues/show_bug.cgi?id=4203 Bye, bearophile
May 18 2010
Steven Schveighoffer wrote: <snip>Unlike some languages, D1 const does not imply static. Which means you are trying to define an S as containing an S, which would then contain another S and so on. This should work:It's implying static in this context according to my testing. Try this at home: ---------- import std.stdio; const S S1 = S(); struct S { float value; static S opCall() { S s; s.value = 42; return s; } const S S2 = S(); } pragma(msg, S.sizeof); pragma(msg, S1.value); pragma(msg, S.S2.value); ----------
May 29 2010
strtr wrote:Should I report these bugs?The general answer to this question is: Yes, as long as * you're sure it's a bug * you can reproduce it in a current version of DMD or GDC * it isn't already reported The bug reporting system is here: http://d.puremagic.com/issues/(and how should I call this first one?)<snip>-- main.d(4): Error: struct main.S no size yet for forward reference main.d(4): Error: struct main.S no size yet for forward reference main.d(11): Error: cannot evaluate opCall() at compile time ----Puzzling. It appears that line 2 is somehow helping the compiler to get it right - and without it, the compiler gets thrown while trying to make sense of the S() you're setting S2 to. But the line numbers you're getting are puzzling in any case. In any case, there's certainly a bug here. <snip>-- run main.exe Error: ArrayBoundsError main.d(8) should be t_def.d(8) ----That's certainly a bug that needs to be reported if it isn't reported already.---- module main; const S S1 = S(); struct S { static S func( S s_ ) out(result){ assert(false,random); } body{ return s_; } const S S2 = func(S()); } void main(){} --The error should be "undefined identifier random".main.d(11): Error: cannot evaluate func((S())) at compile timeIndeed, this is probably a bug along the same lines as the compiler's tendency to treat invalid expressions as being subsequently of type int. Stewart.
May 29 2010