roxen.lists.pike.general

Subject Author Date
答复: Bug when using program as ke 郭雪松zZ x <郭雪松zZ x[at]nirgend> 10-10-2009
 =?utf-8?Q?y_of_mapping?=
How about adding a keyword ' hide_parent' to forbid a class or function access
vars in parent? 
For example:

 class A {
  hide_parent class B {
   mixed b() {
    return A.C;
    //return C;
   }
  }
  hide_parent class C {
  }
 }

If B or C reference any var in A, throw a error.


-----邮件原件-----
发件人: Martin Stjernholm [mailto:<mast[at]lysator.liu.se>] 
发送时间: 2009年10月9日 22:59
收件人: <peterpan[at]wukong.com>
抄送: 'Pike mailinglist'
主题: Re: Bug when using program as key of mapping

<<peterpan[at]wukong.com>> wrote:

> I think it is important to make a constant of class a really
> constant, don’t you think so?

You're right that pike could do a better job in that case, but I
regard it as a lack of optimization rather than a bug. I wouldn't rely
on classes being constant since they easily can get a parent pointer
through internal implementation changes.

It's probably not that easy to fix the optimization you want since the
property of not being constant spreads: Consider in your example that
A.C is changed to refer to a nonconstant in A. Then A.C gets a parent
pointer and is no longer constant, and that causes A.B to refer to a
nonconstant so it gets a parent pointer and becomes nonconstant too. I
reckon this propagation could be problematic in the pike compiler
since it's only two pass and would have to sort it out already in the
first pass.

Anyway, you can work around the problem by using e.g. all_constants():

  class A {
    class B {
      mixed b() {
        return all_constants()->MyA->C;
      }
    }
    class C {
    }
  }

  int main()
  {
    all_constants()->MyA = A;
    werror ("%O\n", functionp (A()->B));
  }

Yes, that's ugly, but it works. Just note that all_constants()
contains all top level identifiers, so watch out so you don't override
something accidentally.


> I see. But it sould still be considered as a bug.
>  
> I modified your class A as following:
>  
> class A {
>  class B {
>   mixed b() {
>    return A.C;
>    //return C;
>   }
>  }
>  class C {
>  }
> }
>
> Since C is a constant of class A, B.b() reference a constant of its parent
scope.
> Why it should be considered as whatever PROGRAM_USES_PARENT ?
>  
> I think A.C has the same position of constants such as "hello", 1,2,3 ...
>  
> If the class referenced A.C become a function, then the classes referenced any
constant string or number should be function too.
>  
> "A program is no more a constant because it reference another constant"? it's
a joke!
>  
>
>
> Xuesong Guo