digitalmars.D.bugs - [Issue 516] New: Mutually calling constructors allowed
- d-bugmail puremagic.com (32/32) Nov 15 2006 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (4/4) Jun 27 2008 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (5/5) Jun 27 2008 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (7/7) Jun 27 2008 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (5/5) Jun 28 2008 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (5/5) Jun 28 2008 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (6/9) Jun 29 2008 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (9/9) Jun 29 2008 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (10/10) Jun 29 2008 http://d.puremagic.com/issues/show_bug.cgi?id=516
- d-bugmail puremagic.com (11/11) Jan 21 2012 http://d.puremagic.com/issues/show_bug.cgi?id=516
http://d.puremagic.com/issues/show_bug.cgi?id=516
Summary: Mutually calling constructors allowed
Product: D
Version: 0.174
Platform: PC
URL: http://www.digitalmars.com/d/class.html
OS/Version: Windows
Status: NEW
Keywords: spec
Severity: normal
Priority: P4
Component: DMD
AssignedTo: bugzilla digitalmars.com
ReportedBy: deewiant gmail.com
OtherBugsDependingO 511
nThis:
The spec states under "Constructors" that "It is illegal for constructors to
mutually call each other", providing a code snippet similar to the following as
a showcase:
class Foo {
this() { this(1); }
this(int i) { this(); } // illegal, cyclic constructor calls
}
void main() {
Foo foo = new Foo();
}
Yet, this code compiles fine, failing at runtime due to a stack overflow.
If the compiler is not meant to detect this, the restriction seems redundant -
such calls will obviously fail at runtime just as though the constructors were
normal functions, which do not suffer from such a restriction. If the compiler
should, however, detect this, then it is a bug that it currently does not.
--
Nov 15 2006
http://d.puremagic.com/issues/show_bug.cgi?id=516 There is no way, in the general case, for the compiler to detect this. --
Jun 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=516 Why not? Java does it. And "this" is bound at static time, not and runtime, and at static time you have all the information needed to detect cycles. --
Jun 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=516
Because this may be declared as:
this();
meaning it's body appears elsewhere. Also, things that appear to be cycles in
static analysis may not be at runtime, like recursive functions.
--
Jun 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- If it's not possible just remove it from the spec. Why was it there in the first place? --
Jun 28 2008
http://d.puremagic.com/issues/show_bug.cgi?id=516 1. Java doesn't allow separate compilation of constructors. 2. Java doesn't allow any flow control before other constructors are called. --
Jun 28 2008
http://d.puremagic.com/issues/show_bug.cgi?id=516If it's not possible just remove it from the spec. Why was it there in the first place?Some parts of the spec can be read as "The language is not required to work correctly if you do ____. If you do and "things" happen, it's your error." --
Jun 29 2008
http://d.puremagic.com/issues/show_bug.cgi?id=516 Therein lies half the problem. The spec should make a clear distinction between things that are actually illegal, things that cause undefined behaviour and things that the compiler may decide are errors if it's clever enough. Moreover, I'd read "mutually calling" as meaning that a loop exists in which constructors call which others, regardless of whether the calls can actually loop at runtime. --
Jun 29 2008
http://d.puremagic.com/issues/show_bug.cgi?id=516 I disagree. I think it is valid to say that something is both illegal and that it result in undefined behavior. I think that somewhere it is said, for example, that it is /illegal/ to have code depend on order of evaluation (this can't be checked, the halting problem can be found in there). Maybe the distinction should be made between things that are illegal and the compiler is required to reject and things that are still illegal but that it needn't detect. --
Jun 29 2008
http://d.puremagic.com/issues/show_bug.cgi?id=516
Walter Bright <bugzilla digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
02:16:40 PST ---
https://github.com/D-Programming-Language/d-programming-language.org/commit/d26103e11b8af546e4bfac71c412a0ecf02aac5d
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 21 2012









d-bugmail puremagic.com 