digitalmars.D.bugs - A strange bug with using functions as args
- BCS (27/27) Sep 15 2005 I have run into what I think is a bug.
- Hasan Aljudy (28/67) Sep 15 2005 This doesn't help much, I tried the following (see below) and it worked
- BCS (2/69) Sep 15 2005
-
Stewart Gordon
(21/22)
Sep 16 2005
- BCS (47/65) Sep 16 2005 I posted that code because it gives general idea of what the bug is in t...
I have run into what I think is a bug.
The code (sort of)
class A
{
int foo(){...} // always returns the same number (in this case)
int bar(int i) {...} // returns a function of only i
int runA()
{
return bar(foo());
}
int runB()
{
int i = foo();
return bar(i);
}
}
void main()
{
A a = new A;
writef(a.runA(), \n);
writef(a.runB(), \n);
}
(This code isn't the code with the bug, that code is 15k+ lines long.)
The bug: A.runA and A.runB return different numbers.
In my actual code storing the function to a temp variable and using that changed
the output.
Any ideas??
Sep 15 2005
This doesn't help much, I tried the following (see below) and it worked
fine.
Maybe it's what the function bar is doing in your code ..
Could you try to provide a more specific test case?
This works fine:
----------------------------------------
import std.stdio;
class A
{
int foo(){ return 5; }
int bar(int i) { return i + 1; }
int runA()
{
return bar(foo());
}
int runB()
{
int i = foo();
return bar(i);
}
}
void main()
{
A a = new A;
writef(a.runA(), \n);
writef(a.runB(), \n);
}
BCS wrote:
I have run into what I think is a bug.
The code (sort of)
class A
{
int foo(){...} // always returns the same number (in this case)
int bar(int i) {...} // returns a function of only i
int runA()
{
return bar(foo());
}
int runB()
{
int i = foo();
return bar(i);
}
}
void main()
{
A a = new A;
writef(a.runA(), \n);
writef(a.runB(), \n);
}
(This code isn't the code with the bug, that code is 15k+ lines long.)
The bug: A.runA and A.runB return different numbers.
In my actual code storing the function to a temp variable and using that
changed
the output.
Any ideas??
Sep 15 2005
I'll try to strip it down but don't hold you'r breath. It's quite involved code.
In article <dgci00$1u4p$1 digitaldaemon.com>, Hasan Aljudy says...
This doesn't help much, I tried the following (see below) and it worked
fine.
Maybe it's what the function bar is doing in your code ..
Could you try to provide a more specific test case?
This works fine:
----------------------------------------
import std.stdio;
class A
{
int foo(){ return 5; }
int bar(int i) { return i + 1; }
int runA()
{
return bar(foo());
}
int runB()
{
int i = foo();
return bar(i);
}
}
void main()
{
A a = new A;
writef(a.runA(), \n);
writef(a.runB(), \n);
}
BCS wrote:
I have run into what I think is a bug.
The code (sort of)
class A
{
int foo(){...} // always returns the same number (in this case)
int bar(int i) {...} // returns a function of only i
int runA()
{
return bar(foo());
}
int runB()
{
int i = foo();
return bar(i);
}
}
void main()
{
A a = new A;
writef(a.runA(), \n);
writef(a.runB(), \n);
}
(This code isn't the code with the bug, that code is 15k+ lines long.)
The bug: A.runA and A.runB return different numbers.
In my actual code storing the function to a temp variable and using that
changed
the output.
Any ideas??
Sep 15 2005
BCS wrote: <snip>(This code isn't the code with the bug, that code is 15k+ lines long.)<snip> If this code doesn't have the bug, then why did you post it? A good idea is to try first to reproduce the bug by writing a short program from scratch. Then, if that fails, then try trimming your program down. This might help you: http://www.physci.org/codes/sscce.jsp (It's actually aimed at being a technique for isolating bugs in your programs, but many of the points are also applicable to writing compiler bug testcases.) Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Sep 16 2005
I posted that code because it gives general idea of what the bug is in the hope that someone would recognize it a similar to something they had encountered. I plan to try to strip down the real code but I expect it will not be vary fruitful. My best guess is that it is a compiler bug (or something that will make me feel vary stupid) or some such thing. Below is a better approximation of the real code. (This actually does a simpler case of what the real thing does.) In the real thing, on line 6, storing the value of the 2nt argument to a temp variable before the call changes how things run. This code also doesn’t have the bug. (Sorry) #import std.math; #import std.stdio; #class Taylor #class Newton j*(time*time*time/6); } #void main() One candidate for a cause is that the compiler Is inlineing the calls at line 6 and time is getting changed some where in the first call. In article <dgf13m$1a2m$1 digitaldaemon.com>, Stewart Gordon says...If this code doesn't have the bug, then why did you post it? A good idea is to try first to reproduce the bug by writing a short program from scratch. Then, if that fails, then try trimming your program down. This might help you: http://www.physci.org/codes/sscce.jsp (It's actually aimed at being a technique for isolating bugs in your programs, but many of the points are also applicable to writing compiler bug testcases.) Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Sep 16 2005









BCS <BCS_member pathlink.com> 