Re: Three legitimate bugs? (D1.061)

2010-05-29 Thread Stewart Gordon

Steven Schveighoffer wrote:

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);
--


Re: Three legitimate bugs? (D1.061)

2010-05-29 Thread Stewart Gordon

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.



--
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.


Re: Three legitimate bugs? (D1.061)

2010-05-18 Thread bearophile
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


Re: Three legitimate bugs? (D1.061)

2010-05-18 Thread Don

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.


Re: Three legitimate bugs? (D1.061)

2010-05-18 Thread Don

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.


Re: Three legitimate bugs? (D1.061)

2010-05-17 Thread bearophile
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


Re: Three legitimate bugs? (D1.061)

2010-05-17 Thread Steven Schveighoffer
On Mon, 17 May 2010 15:31:23 -0400, bearophile   
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


Re: Three legitimate bugs? (D1.061)

2010-05-17 Thread bearophile
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


Re: Three legitimate bugs? (D1.061)

2010-05-17 Thread Steven Schveighoffer

On Mon, 17 May 2010 10:28:47 -0400, strtr  wrote:


== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article

On Sat, 15 May 2010 16:15:23 -0400, strtr  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


Re: Three legitimate bugs? (D1.061)

2010-05-17 Thread strtr
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Sat, 15 May 2010 16:15:23 -0400, strtr  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?



Re: Three legitimate bugs? (D1.061)

2010-05-17 Thread Steven Schveighoffer

On Sat, 15 May 2010 16:15:23 -0400, strtr  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


Re: Three legitimate bugs? (D1.061)

2010-05-15 Thread strtr
== Quote from bearophile (bearophileh...@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..


Re: Three legitimate bugs? (D1.061)

2010-05-15 Thread bearophile
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


Three legitimate bugs? (D1.061)

2010-05-15 Thread strtr
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