Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a1afde428b359b516d3ce98dd39a86a512d54d59
Ticket: 2530725fffffffffffffffffffffffffffffffff
Surprising behaviour of empty constructor
User & Date: apnadkarni on 2009-01-23 09:36:23
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    
    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
    
  4. foundin changed to: "obsolete: 8.6b1"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "apnadkarni"
  10. subsystem changed to: "35. TclOO Package"
  11. title changed to: "Surprising behaviour of empty constructor"
  12. type changed to: "Bug"