Annoying module name / typename conflict

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Apr 2 15:08:42 PDT 2012


Code:
	// S.d
	struct S {
		int x;
		this(int _x) { x = _x; }
	}

	// test.d
	class T {
		S s;
		this(S _s) { s = _s; }
	}

	void main() {
		auto t = new T(S(1)); // this is line 10
	}

Compiler error:

test.d(10): Error: function expected before (), not module S of type void
test.d(10): Error: constructor test.T.this (S _s) is not callable using argument types (_error_)

The error goes away if either struct S or S.d is renamed.

Is there any reason whatsoever that the compiler should resolve "S" to
the module rather than the struct defined by the eponymous module?

Given that in D, private applies per module, it's quite often desirable
to name the module after the single class/struct that it defines.
However, this name conflict makes this scheme rather painful to use. :-(


T

-- 
This is not a sentence.


More information about the Digitalmars-d mailing list