Consider:
% oo::class create foo {constructor {} {}}
::foo
% set f [foo new]
::oo::Obj12
% set g [foo new a b c]
::oo::Obj13
I'd expect the second attempt to create an object to fail because
there are too many arguments.
Also:
% oo::class create foo {constructor {a} {}}
::foo
% set f [foo new]
::oo::Obj12
% set f [foo new a b c]
::oo::Obj13
I'd expect both attempts to create objects to fail because neither
specifies the correct number of arguments.
Have I misunderstood something (if so, what) or is there a bug here?
* Joerg Mertens <joerg-mertens@t-online.de>
| Alan Grunwald <nospam.nurdglaw@gmail.com> writes:
| > % oo::class create foo {constructor {a} {}}
| > ::foo
| > % set f [foo new]
| > ::oo::Obj12
| > % set f [foo new a b c]
| > ::oo::Obj13
| >
| > I'd expect both attempts to create objects to fail because neither
| > specifies the correct number of arguments.
| >
| > Have I misunderstood something (if so, what) or is there a bug here?
| Looks like the constructor is not even created if the body is empty. As
| soon as you put something in the body the arguments are checked:
Even an comment is sufficient to trigger this:
% oo::class create foo {constructor {} {#;}}
::foo
% set g [foo new a b c]
wrong # args: should be "foo new"
But I would file "not checking the arguments" under 'bug' anyway...
R'
On 12/03/2024 11:19, Ralf Fassel wrote:
* Joerg Mertens <joerg-mertens@t-online.de>
| Alan Grunwald <nospam.nurdglaw@gmail.com> writes:
| > % oo::class create foo {constructor {a} {}}
| > ::foo
| > % set f [foo new]
| > ::oo::Obj12
| > % set f [foo new a b c]
| > ::oo::Obj13
| >
| > I'd expect both attempts to create objects to fail because neither
| > specifies the correct number of arguments.
| >
| > Have I misunderstood something (if so, what) or is there a bug here?
| Looks like the constructor is not even created if the body is empty. As
| soon as you put something in the body the arguments are checked:
Even an comment is sufficient to trigger this:
% oo::class create foo {constructor {} {#;}}
::foo
% set g [foo new a b c]
wrong # args: should be "foo new"
But I would file "not checking the arguments" under 'bug' anyway...
R'
Thanks Joerg, Ralf. I didn't realise that the default constructor (if
none was specified) would accept an arbitrary number of arguments.
I'll raise a bug report about the differing behaviour between a
constructor with and without a body.
Alan
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 916 |
Nodes: | 10 (1 / 9) |
Uptime: | 49:20:52 |
Calls: | 12,172 |
Calls today: | 2 |
Files: | 186,522 |
Messages: | 2,234,684 |