D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1359 - Can call non implemented functions
Summary: Can call non implemented functions
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, wrong-code
Depends on:
Blocks: 340
  Show dependency treegraph
 
Reported: 2007-07-20 18:15 UTC by Moritz Warning
Modified: 2014-02-16 15:21 UTC (History)
3 users (show)

See Also:


Attachments
alternative testcase (1.63 KB, text/plain)
2007-08-11 08:45 UTC, Moritz Warning
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Moritz Warning 2007-07-20 18:15:01 UTC
In this following example we can call Foo.get
even it is not implemented.
The program compiles and runs without problems, but shouldn't.
When Foo.get is implemented it also never get called.

The compiler recognizes the bug when the return type
for get isn't a template or interfaces Node and Nodes
changes places.


module Main;

class Bar(T)
{
}

//program compiles but crashes when interface is empty
interface Node : Nodes
{
	void print();
}

interface Nodes
{
	public:
	
	Bar!(Node) get();
}

class Foo : Node
{

public:
	
	void print() {  }
	/*
	//never get called when implemented
	Bar!(Node) get()
	{
		return null;
	}
	*/
}

void main(char[][] args)
{
	Node foo = new Foo;
	
	foo.get();
}
Comment 1 Moritz Warning 2007-08-11 08:45:32 UTC
Created attachment 169 [details]
alternative testcase

This is another testcase that show that applications can silently change behavior ,crash or just don't work only by switching the order of declaration of two interfaces. It doesn't matter if the interfaces are defined in another file.
Comment 2 Rainer Schuetze 2009-09-18 01:45:16 UTC
Seems to work fine with DMD 1.047 and DMD 2.032. I haven't tested the additional alternative testcase, though (because of the tango usage).
Comment 3 Don 2009-09-18 15:12:08 UTC
Fixed in 1.029 or 1.030.