Bug 6573 - It should be possible to inherit "fake" classes
: It should be possible to inherit "fake" classes
Status: RESOLVED FIXED
: Pike
Compiler
: 7.9
: All All
: P3 (normal) enhancement
: ---
Assigned To:
:
:
:
  Show dependency treegraph
 
Reported: 2012-10-21 22:02 CET by
Modified: 2012-10-27 17:41 CET (History)
Scrum Prio:
In scrum?: ---
Story included in sprints:
Unplanned in sprints:


Attachments


Description From 2012-10-21 22:02:41 CET
It is possible to use the name of a "fake" class (really an object) when
declaring a variable.  However, when instead declaring an inherit the behaviour
is not the expected.

Example:

---8<--- A.pmod ---8<---
static class Meta(string name)
{
  string a() { return "+"+name; }

  static class I(string value)
  {
    string a() { return "-"+name+":"+value; }
    int x() { return 0; }
  }

  static program cast(string type) { return type=="program" && I; }

  static I `()(string v)
  {
    return I(v);
  }
}

Meta B = Meta("B");
---8<---

---8<--- b.pike ---8<---
import .A;

class C { inherit B; }

void main()
{
  B b = B("*");
  C c = C("%");
  write("%O %O\n", _typeof(b)<=typeof(b), b->a());
  write("%O %O\n", _typeof(c)<=typeof(b), c->a());
}
---8<---

Running b.pike gives the output

1 "-B:*"
0 "+%"

But the expected output is

1 "-B:*"
1 "-B:%"

compiler_do_inherit needs to check either the `() lfun (which is what the
variable declaration does) or the cast lfun instead of just doing
object_program().
------- Comment #1 From 2012-10-27 15:51:15 CET -------
The cast operator now calls object_program() for objects if they lack
lfun::cast() or it returns UNDEFINED.
------- Comment #2 From 2012-10-27 17:41:24 CET -------
Fixed in Pike 7.9:

 $ ./pike bug6573/b.pike 
1 "-B:*"
1 "-B:%"

Note

You need to log in before you can comment on or make changes to this bug.