|
2009-02-15
| ||
| 16:00 | • Closed ticket [2530725fff]: Surprising behaviour of empty constructor plus 7... artifact: 64df5bf4a4 user: dkf | |
|
2009-01-28
| ||
| 22:30 | • Ticket [2530725fff]: 4 changes artifact: c543924dbb user: dkf | |
|
2009-01-23
| ||
| 09:36 | • New ticket [2530725fff]. artifact: a1afde428b user: apnadkarni | |
Surprising behaviour of empty constructor
Closed / Invalid2530725fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2009-01-23 09:36:23
I found the behaviour exhibited in the wish session below surprising. Defining an empty constructor behaves as though no constructor was defined for the class at all. In particular,
- I would expect the derived class constructor to "hide" the superclass constructor and not execute it since there is no next call. Creating a D object is seen to run the C construtor
- I would expect info class constructor D to return a pair containing the arg a and an empty body
- A constructor defined with an empty body behaves the same as a constructor defined with the statement "next" (or similar, there might be differences in presence mixins). That does not seem right
- Adding a comment to a body changes the code that is executed - see the difference between behaviour of class D and E, the only difference being addition of a comment. This to me is the biggest NO-NO.
(web) 2 % oo::class create C {
> constructor {a} {set ::x $a}
> }
::C
(web) 3 % oo::class create D {
> superclass C
> constructor {a} {}
> }
::D
(web) 4 % info class constructor D
(web) 5 % info class constructor C
a {set ::x $a}
(web) 6 % D create d
wrong # args: should be "D create d a"
(web) 7 % D create d 1
::d
(web) 8 % set x
1
(web) 10 % oo::class create E {
> superclass C
> constructor {a} { # Just a comment }
> }
::E
(web) 11 % set x 0
0
(web) 12 % E create e
wrong # args: should be "E create e a"
(web) 13 % E create e abc
::e
(web) 14 % set x
0
/Ashok
dkfplain2009-01-28 22:30:47
If the body of a constructor (or destructor) is the empty string, the constructor(/destructor) is deleted. This is documented.
dkfplain2009-02-15 16:00:45
allow_comments - 1
Log in (anonymous is fine) to add a comment.