Wrong method called.

Dave Dave_member at pathlink.com
Sun Mar 5 09:43:15 PST 2006


In article <Pine.LNX.4.64.0603041438430.30259 at bellevue.puremagic.com>, Brad
Roberts says...
>
>On Sat, 4 Mar 2006, alan wrote:
>
>> In article <ducnmk$rv$4 at digitaldaemon.com>, Walter Bright says...
>> >
>> >It's not a bug. The order in the import file *must* match the order in the 
>> >import's compiled object file. In the example presented, the order in the 
>> >import file is changed (via a command line switch) to be different from what 
>> >it was in the object file. 
>> >
>> >
>> 
>> dmd b.d a.d -c
>> 
>> dmd main.d a.obj b.obj
>> Error: AssertError Failure a.d(5)
>> 
>> dmd main.d b.obj a.obj
>> Error: AssertError Failure a.d(5)
>> 
>> ============================================
>> 
>> dmd a.d b.d -c
>> 
>> dmd main.d a.obj b.obj
>> Bar.bar()
>> 
>> dmd main.d b.obj a.obj
>> Bar.bar()
>> 
>> ============================================
>> 
>> dmd main.d a.d b.d
>> Bar.bar()
>> 
>> dmd main.d b.d a.d
>> Bar.bar()
>> 
>> 
>> OK, it's not a bug, it's a feature! I believe we now know why compiling object
>> modules seperately causes problems. Walter, I think you have a big problem here.
>
>Careful.. don't confuse the original topic here with a different topic.  
>The start of this is changing a module such that it doesn't match the 
>.obj/.o being linked in.  Your example is order of linking.  If you lie to 
>the compiler about the contents of the compiled code by changing the 
>header, you're out of luck in general.
>

The OP was demonstrating a problem that can manifest itself in many ways with
versioning, making bugs caused by this hard to find and fix (because the program
might not crash). For example:

module a;
import b, std.stdio;
void main()
{
B b = new B;
writefln(b.foo(10));
}

module b;
class B
{
version(bar)
int bar(int x) { return x + x; }
int foo(int x) { return x * x; }
}

# dmd -c -version=bar b.d ; dmd -quiet a.d b.o ; a
20

Like the OP, DMC and also VC++ will call the correct function with equivalent
code.

I'm sure this will become a problem with library users not building their apps.
with the same compiler conditionals that were used to build the library. So if
it is something that wouldn't greatly complicate D compilers (or drastically
effect performance in calling virtual methods) then it would be a nice to have
change.

- Dave





More information about the Digitalmars-d-bugs mailing list