Thread overview |
---|
November 15, 2006 [Issue 516] New: Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
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. -- |
June 28, 2008 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- Comment #1 from bugzilla@digitalmars.com 2008-06-27 20:12 ------- There is no way, in the general case, for the compiler to detect this. -- |
June 28, 2008 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- Comment #2 from ary@esperanto.org.ar 2008-06-27 20:33 ------- 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. -- |
June 28, 2008 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- Comment #3 from bugzilla@digitalmars.com 2008-06-27 21:58 ------- 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. -- |
June 28, 2008 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- Comment #4 from matti.niemenmaa+dbugzilla@iki.fi 2008-06-28 03:52 ------- If it's not possible just remove it from the spec. Why was it there in the first place? -- |
June 28, 2008 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- Comment #5 from bugzilla@digitalmars.com 2008-06-28 04:52 ------- 1. Java doesn't allow separate compilation of constructors. 2. Java doesn't allow any flow control before other constructors are called. -- |
June 29, 2008 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- Comment #6 from shro8822@vandals.uidaho.edu 2008-06-29 16:46 ------- (In reply to comment #4) > If 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." -- |
June 29, 2008 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- Comment #7 from smjg@iname.com 2008-06-29 17:04 ------- 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. -- |
June 29, 2008 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 ------- Comment #8 from shro8822@vandals.uidaho.edu 2008-06-29 17:21 ------- 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. -- |
January 21, 2012 [Issue 516] Mutually calling constructors allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=516 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED --- Comment #9 from Walter Bright <bugzilla@digitalmars.com> 2012-01-21 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: ------- |
Copyright © 1999-2021 by the D Language Foundation