Type inference oddity with this_program
Chris Angelico <[email protected]>
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <CAPTjJmqdqemAn+Qrqg1U+H4_uNf6kAXF7h_w95C6YfC2viQPbg@mail.gmail.com> |
Example code:
constant label_xyz="XYZ";
int main()
{
foreach (indices(this_program),string const)
{
//program me=this_program; write("%O\n",me[const]);
write("%O\n",this_program[const]);
}
}
This produces the following error:
thisprog.pike:8:Indexing on illegal type.
thisprog.pike:8:Got : function( : object(is
program(/home/rosuav/thisprog.pike))).
thisprog.pike:8:Index : string.
Pike: Failed to compile script.
If the program is retained in a separate variable (see the
commented-out alternative), it works fine, and correctly fetches up
the value of the constant. Using this[const] also works fine. But
this_program[const], for some reason, is thought to be looking at a
function (which it kinda is; calling a program will return an object
of that type, so the signature is more-or-less right).
This oddity is visible on Pike 7.8.700 on Windows and 8.0.1 on Linux.
Is this a bug, or am I misunderstanding this_program?
ChrisA