Re: Phix syntax

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

Note: It appears that you may be able to have two (or more?) routines by the same name within a class without triggering an error.
So how does this work?

It doesn't, you've found a bug (thanks).

If you declare a second name field, as expected you get a "duplicate" compilation error.

However all methods are "virtual", in the sense that they can be overidden.
If your base Widget class has a set_name() procedure, and your Window class also has one, it quietly replaces it.
(And before you ask, there isn't any kind of super.get_name(), or any firm plans to add such, as yet.)
(For now, I'd just suggest putting any such code in a private get_name_() and invoking that directly, twice.)
The bug(s) are: it should check that any such replacement has the right type/signature, and that whatever it is
replacing is from an extended/base class rather than the current one. As it stands, those declarations store an
integer routine_id in the string name[1], and you'd need a bit of indirection/sleight of hand to fake out the
compiler such that you could invoke (the second) via call_func (the procedure's routine_id has already been lost).

[1] Technically, that is, in the default for the name field, ie some internal {0,"",3074} ==> {0,3076,3074}, so
it is neatly sidestepping all the usual builtin typechecking mechanisms, and of course new() totally trusts the
integrity of said internal.

PS. I'm committed to this idea now, but with no timescale as yet.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu