D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16160 - Selective imports in aggregate types shadow methods
Summary: Selective imports in aggregate types shadow methods
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-06-10 20:13 UTC by Robert Schadek
Modified: 2022-11-09 14:52 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Robert Schadek 2016-06-10 20:13:13 UTC
struct Foo {
	import std.array : empty;

	@property bool empty() {
		return true;
	}
}

unittest {
	Foo f;
	assert(f.empty);
}

Error: expression f.empty of type void does not have a boolean value
It seams like the import of std.array.empty is shadowing the empty @property.
Moving the import out of the struct fixes the problem.
Comment 1 Vladimir Panteleev 2017-07-19 07:09:43 UTC
Worth noting that before https://github.com/dlang/dmd/pull/2417, the error message made a bit more sense:

test.d(4): Error: function test.Foo.empty conflicts with alias test.Foo.empty at test.d(2)

The current error message mentions that f.empty is of type void, which is misleading.
Comment 2 basile-z 2019-03-30 13:58:04 UTC
Works with parens:

    assert(f.empty());

Because the compiler can figure out that empty() is a member func, beforehand.
And @property can be dropped from the test case.
Comment 3 RazvanN 2022-11-09 14:52:11 UTC
Not anymore. This code compiles now. Closing as WORKSFORME.