Issue Details (XML | Word | Printable)

Key: BOO-1040
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Cedric Vivier
Reporter: Cedric Vivier
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

Calling a constructor overload calls $initializer$ again

Created: 02/Jun/08 04:15 PM   Updated: 22/Jan/09 09:22 AM   Resolved: 03/Jun/08 01:29 PM
Return to search
Component/s: Compiler
Affects Version/s: 0.8.2, 0.9
Fix Version/s: 0.9

Time Tracking:
Not Specified

Testcase included: yes


 Description  « Hide

(and thus resets all fields with initializers)

Following code :

class Test:
     _x = "pre"

     def constructor():
           print _x

     def constructor(x as string):
           _x = x
           self()

Test("post")

Shows "pre", whereas it should obviously show "post".

We should either :
1) disallow using self() at any other position than first in the block (as what C# does in practice).
2) add a $initialized$ boolean field so that $initializer$ is executed only once.

(2) sounds more boo-ish imho, we could add the field only when there is more than one constructor on the object.



Cedric Vivier made changes - 02/Jun/08 04:16 PM
Field Original Value New Value
Description (and thus resets all fields with initializers)

Following code :

{code}
class Test:
     _x = "pre"

     def constructor():
           print _x

     def constructor(x as string):
           _x = pre
           self()

Test("post")
{code}

Shows "pre", whereas it should obviously show "post".

We should either :
1) disallow using self() at any other position than first in the block (as what C# does in practice).
2) add a $initialized$ boolean field so that $initializer$ is executed only once.


(2) sounds more boo-ish imho, we could add the field only when there is more than one constructor on the object.


(and thus resets all fields with initializers)

Following code :

{code}
class Test:
     _x = "pre"

     def constructor():
           print _x

     def constructor(x as string):
           _x = x
           self()

Test("post")
{code}

Shows "pre", whereas it should obviously show "post".

We should either :
1) disallow using self() at any other position than first in the block (as what C# does in practice).
2) add a $initialized$ boolean field so that $initializer$ is executed only once.


(2) sounds more boo-ish imho, we could add the field only when there is more than one constructor on the object.


Cedric Vivier made changes - 02/Jun/08 04:23 PM
Summary Using self() within a constructor overload calls $initializer$ again Calling a constructor overload calls $initializer$ again
Cedric Vivier added a comment - 03/Jun/08 01:29 PM

fixed in rev. 2992


Cedric Vivier made changes - 03/Jun/08 01:29 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Rodrigo B. de Oliveira made changes - 22/Jan/09 09:22 AM
Affects Version/s 0.9 [ 13816 ]
Fix Version/s 0.8.3 [ 13815 ]
Fix Version/s 0.9 [ 13816 ]