1570 – Wrong return for address operator

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1570 - Wrong return for address operator
Summary: Wrong return for address operator
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, spec, wrong-code
Depends on:
Blocks:
Reported: 2007年10月11日 02:23 UTC by PetSerAl
Modified: 2015年06月09日 01:14 UTC (History)
4 users (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 PetSerAl 2007年10月11日 02:23:03 UTC
import std.stdio;
void main()
{ 
	b v=new b;
	v.f;
	v.a.f;
	(&v.f)();
	(&v.a.f)();
} 
class a
{
	void f()
	{
		writeln("class a");
	}
}
class b:a
{
	void f()
	{
		writeln("class b");
	}
}
This program write:
class b
class a
class b
class b
Comment 1 Stewart Gordon 2007年11月08日 08:04:03 UTC
What is v.a and where's it documented? Should it work?
Comment 2 Stewart Gordon 2008年09月09日 14:56:21 UTC
Since I can't at the moment find any evidence in the spec that v.a is a valid expression, I'm marking this as accepts-invalid. If I'm wrong, please show me where it's defined.
Comment 3 Jarrett Billingsley 2008年09月09日 15:17:33 UTC
(In reply to comment #2)
> Since I can't at the moment find any evidence in the spec that v.a is a valid
> expression, I'm marking this as accepts-invalid. If I'm wrong, please show me
> where it's defined.
> 
a is the class a, which for some reason is accessible through a reference to class b. If you capitalize the class names it makes it a lot clearer.
I think it might actually be somehow related to the thing about typeof(this) and non-virtual calls made on the expressions page:
http://www.digitalmars.com/d/1.0/expression.html
In any case it doesn't seem to be explicitly documented, but I wonder if there's a use for it. It breaks encapsulation by allowing you to manually access a base class's implementation of a method, and with single inheritance there's no need to select the implementation from several base classes.
Comment 4 Kenji Hara 2011年06月18日 02:40:54 UTC
It seems to me that sample code is valid.
Because dmd frontend has v.a as DotTypeExp explicitly and keeps its information,
then resolve overloads of f as A.f.
Therefore v.a.f should call A.f is right (but not documented) behavior.
-> Remove 'accepts-invalid' from keywords.
And generated code from (&v.a.f)() calls B.f is wrong-code.
It should be fixed.
Comment 5 Stewart Gordon 2011年06月18日 02:59:01 UTC
(In reply to comment #4)
> It seems to me that sample code is valid.
> Because dmd frontend has v.a as DotTypeExp explicitly and keeps its
> information,
a is not a member of v. So the expression is invalid. Unless you can find something in the spec that states otherwise.
> then resolve overloads of f as A.f.
> Therefore v.a.f should call A.f is right (but not documented) behavior.
> -> Remove 'accepts-invalid' from keywords.
How can a case of the compiler accepting something that the spec doesn't allow be neither accepts-invalid nor a spec issue?
Comment 6 Walter Bright 2011年06月28日 12:45:57 UTC
v.a is supposed to work, and it means look up the name in the scope of the base class a.
Comment 7 Stewart Gordon 2011年06月28日 13:00:09 UTC
(In reply to comment #6)
> v.a is supposed to work, and it means look up the name in the scope of the base
> class a.
Nice try. Now supply a link to the relevant bit of the spec.
Comment 8 Walter Bright 2011年06月28日 13:28:55 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > v.a is supposed to work, and it means look up the name in the scope of the base
> > class a.
> Nice try. Now supply a link to the relevant bit of the spec.
If it's not in the spec, it needs to be. Wanna do a pull request?


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