digitalmars.D.learn - Three legitimate bugs? (D1.061)
- strtr <strtr spam.com> May 15 2010
- bearophile <bearophileHUGS lycos.com> May 15 2010
- strtr <strtr spam.com> May 15 2010
- "Steven Schveighoffer" <schveiguy yahoo.com> May 17 2010
- strtr <strtr spam.com> May 17 2010
- bearophile <bearophileHUGS lycos.com> May 17 2010
- bearophile <bearophileHUGS lycos.com> May 17 2010
- Don <nospam nospam.com> May 18 2010
- Don <nospam nospam.com> May 18 2010
- bearophile <bearophileHUGS lycos.com> May 18 2010
- Stewart Gordon <smjg_1998 yahoo.com> May 29 2010
- "Steven Schveighoffer" <schveiguy yahoo.com> May 17 2010
- "Steven Schveighoffer" <schveiguy yahoo.com> May 17 2010
- Stewart Gordon <smjg_1998 yahoo.com> May 29 2010
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(8): Error: __error <---# should be assert failure #
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:Should I report these bugs?
(and how should I call this first one?)
Forward reference error with struct opCall and const Let's see how much time it takes to reach 5000 bugs :-) Bye, bearophile
lets hope a while ;) Although I do like the search..
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: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 ----
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
But why would uncommenting S1 result in compilable code?
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
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: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
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.
May 18 2010
Don wrote:bearophile wrote: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
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.
D'oh, should read the title. This was a D1 question. Yes it's intentional, and yes it's confusing.
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
On Mon, 17 May 2010 10:28:47 -0400, strtr <strtr spam.com> wrote:== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleOn 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 ----
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
But why would uncommenting S1 result in compilable code?
Hm... that's a good question. I guess my belief is wrong. And that would imply that my code doesn't compile... -Steve
May 17 2010
On Mon, 17 May 2010 15:31:23 -0400, bearophile <bearophileHUGS lycos.com> wrote: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.
No, I was simply wrong :) I think it's by design. Which means the original bug report is valid. -Steve
May 17 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?)
-- 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(){} -- main.d(8): Error: __error <---# should be assert failure #
The error should be "undefined identifier random".main.d(11): Error: cannot evaluate func((S())) at compile time
Indeed, 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









strtr <strtr spam.com> 