www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error not callable with argument types but types matches

reply Sliya <sliya nowhere.com> writes:
Hello,

I have some troubles solving this compilation error:

Error: constructor cell.Cell.this (int x, int y, Noise noise) is 
not callable using argument types (int, int, Perlin)

The thing is Perlin implements the Noise interface.

Here is the line from cell.d throwing this error:

_terrain[h][w] = new Cell(w+offsetX,h+offsetY, 
Perlin.getInstance);

Here is the Cell constructor:
this(int x, int y, Noise noise) {
	_height = noise.getValue(x,y);
	_hasTree = uniform(0,2) == 0 ? true : false;
}

Perlin is a singleton with following code:
class Perlin : Noise{
	private:
		static Perlin _instance = null;
		this(){//some code}

	public:

		static Perlin getInstance(){
			if(_instance is null){
				_instance = new Perlin();
			}
			return _instance;
		}
}

The weirdest part is when I change the return type of the 
getInstance to Noise:
static Noise getInstance();

I get this error message:
Error: constructor cell.Cell.this (int x, int y, Noise noise) is 
not callable using argument types (int, int, Noise)

What am I doing wrong ?
Nov 07 2015
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
Are you sure it is the same Noise on both sides? Two separate 
imports might define different interfaces with the same name and 
that could be what's causing the confusion here.
Nov 07 2015
parent reply Sliya <sliya nowhere.com> writes:
On Saturday, 7 November 2015 at 17:27:00 UTC, Adam D. Ruppe wrote:
 Are you sure it is the same Noise on both sides? Two separate 
 imports might define different interfaces with the same name 
 and that could be what's causing the confusion here.
You sir are my savior ! I imported "Noise" instead of "noise". What I don't get is that I have no file named "Noise", so why doesn't the line import Noise; throws a compilation error ?
Nov 07 2015
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 7 November 2015 at 17:31:53 UTC, Sliya wrote:
 I imported "Noise" instead of "noise". What I don't get is that 
 I have no file named "Noise", so why doesn't the line import 
 Noise; throws a compilation error ?
Are you on Windows? File loads there ignore case by name so the compiler tries to load "Noise.d" and Windows will let you open "noise.d" too. To avoid this kind of thing, I always put a `module your.name;` at the top of every file so you get the name right there in the D language too.
Nov 07 2015
parent reply Sliya <sliya nowhere.com> writes:
On Saturday, 7 November 2015 at 17:43:02 UTC, Adam D. Ruppe wrote:
 Are you on Windows? File loads there ignore case by name so the 
 compiler tries to load "Noise.d" and Windows will let you open 
 "noise.d" too.

 To avoid this kind of thing, I always put a `module your.name;` 
 at the top of every file so you get the name right there in the 
 D language too.
I am on Mac OS, but I still don't get it. If the import was not case-sensitive, I would not have any error since the good file would have been loaded... Here I have no error saying file not found yet the file is not loaded. I'd love to know what really happens. But thanks !
Nov 07 2015
parent anonymous <anonymous example.com> writes:
On 08.11.2015 08:17, Sliya wrote:
 I am on Mac OS, but I still don't get it. If the import was not
 case-sensitive, I would not have any error since the good file would
 have been loaded... Here I have no error saying file not found yet the
 file is not loaded. I'd love to know what really happens.
The file system is case insensitive. That means when dmd opens noise.d or Noise.d it gets the same contents both times. So both `import noise;` and `import Noise;` succeed. But the module name is case sensitive. `import noise;` results in a module `noise`, while `import Noise;` results in a module `Noise`. And they're not the same. They're different modules. So when cell.d does `import Noise;` and perlin.d does `import noise;`, then they're using two different, incompatible Noise interfaces.
Nov 08 2015