325 – Overriding members and overloading with alias causes bogus error messages in with().

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 325 - Overriding members and overloading with alias causes bogus error messages in with().
Summary: Overriding members and overloading with alias causes bogus error messages in ...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2006年09月06日 06:51 UTC by Chris Miller
Modified: 2015年06月09日 05:14 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Chris Miller 2006年09月06日 06:51:08 UTC
I finally was able to reproduce this problem with a small example:
// Code begin
class Base
{
	private char[] myfoo;
	private char[] mybar;
	
	// Get/set properties that will be overridden.
	void foo(char[] s) { myfoo = s; }
	char[] foo() { return myfoo; }
	
	// Get/set properties that will not be overridden.
	void bar(char[] s) { mybar = s; }
	char[] bar() { return mybar; }
}
class Derived: Base
{
	alias Base.foo foo; // Bring in Base's foo getter.
	override void foo(char[] s) { super.foo = s; } // Override foo setter.
}
void main()
{
	Derived d;
	with(d = new Derived)
	{
		foo = "hi"; // Error! Due to the alias up there.
		d.foo = "hi"; // Works
		bar = "hi";
	}
}
// Code end
DMD 0.161 through 0.166 output: test.d(26): need 'this' to access member text
I was able to find a workaround, simply put the alias after the function in the class instead of before.
Comment 1 Thomas Kühne 2006年09月07日 03:00:26 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
d-bugmail@puremagic.com schrieb am 2006年09月06日:
> http://d.puremagic.com/issues/show_bug.cgi?id=325 
> I finally was able to reproduce this problem with a small example:
>
> // Code begin
> class Base
> {
> private char[] myfoo;
> private char[] mybar;
>
> // Get/set properties that will be overridden.
> void foo(char[] s) { myfoo = s; }
> char[] foo() { return myfoo; }
>
> // Get/set properties that will not be overridden.
> void bar(char[] s) { mybar = s; }
> char[] bar() { return mybar; }
> }
>
> class Derived: Base
> {
> alias Base.foo foo; // Bring in Base's foo getter.
> override void foo(char[] s) { super.foo = s; } // Override foo setter.
> }
>
> void main()
> {
> Derived d;
> with(d = new Derived)
> {
> foo = "hi"; // Error! Due to the alias up there.
> d.foo = "hi"; // Works
> bar = "hi";
> }
> }
> // Code end
>
> DMD 0.161 through 0.166 output: test.d(26): need 'this' to access member text
>
> I was able to find a workaround, simply put the alias after the function in the
> class instead of before.
Added to DStress as
http://dstress.kuehne.cn/run/w/with_15_A.d
http://dstress.kuehne.cn/run/w/with_15_B.d
http://dstress.kuehne.cn/run/w/with_15_C.d
http://dstress.kuehne.cn/run/w/with_15_D.d
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFE/9QJLK5blCcjpWoRAnIYAKCpTEVbTXmI9N8OnF5JZ8MZq6mxWwCgrUbq
Jh4GAQ662tCJbyKFm80A3bg=
=CsG9
-----END PGP SIGNATURE-----
Comment 2 Walter Bright 2006年09月19日 15:28:42 UTC
Fixed in DMC 0.167.


AltStyle によって変換されたページ (->オリジナル) /