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 <[email protected]>
| Alan Grunwald <[email protected]> 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 <[email protected]>
| Alan Grunwald <[email protected]> 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
On 14/03/2024 09:52, Alan Grunwald wrote:
On 12/03/2024 11:19, Ralf Fassel wrote:
* Joerg Mertens <[email protected]>
| Alan Grunwald <[email protected]> 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
I've raised ticket [7a0f53f4] in the core fossil repo - I hope that's
the right place.
In the course of reformulating the example, I discovered that a single
space is sufficient to cause he arguments to be checked.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 935 |
Nodes: | 10 (0 / 10) |
Uptime: | 41:52:05 |
Calls: | 12,326 |
Calls today: | 1 |
Files: | 186,571 |
Messages: | 2,265,146 |