Jump to page: 1 2
Thread overview
Three legitimate bugs? (D1.061)
May 15, 2010
strtr
May 15, 2010
bearophile
May 15, 2010
strtr
May 17, 2010
strtr
May 17, 2010
bearophile
May 17, 2010
bearophile
May 18, 2010
Don
May 18, 2010
Don
May 18, 2010
bearophile
May 29, 2010
Stewart Gordon
May 29, 2010
Stewart Gordon
May 15, 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 article
> strtr Wrote:
> > Should I report these bugs?
> Yes, add them to bugzilla. The third one is especially cute.
Was kind of expecting you to correct me or point me to the corresponding bugzillas ;D

> > (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
As it is really time consuming to construct test cases out of large projects,
lets hope a while ;)
Although I do like the search..
May 17, 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 article
> 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

But why would uncommenting S1 result in compilable code?

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 article
>> 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
>
> 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
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:
>
>> 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
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 18, 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.
« First   ‹ Prev
1 2