#389: subs with :method should not be entered as symbols in the namespace
----------------------+-----------------------------------------------------
 Reporter:  pmichaud  |       Owner:  allison 
     Type:  bug       |      Status:  assigned
 Priority:  critical  |   Milestone:          
Component:  core      |     Version:  trunk   
 Severity:  high      |    Keywords:          
     Lang:  perl6     |       Patch:  new     
 Platform:            |  
----------------------+-----------------------------------------------------

Comment(by allison):

 Sorry folks, but this is the wrong fix. It sets the sub's ns_entry_name to
 an empty string, then calls 'Parrot_store_sub_in_namespace'. But,
 'Parrot_store_sub_in_namespace' is also what stores methods on the class.
 (It extracts sub->ns_entry_name, then calls 'Parrot_store_global_n' which
 calls 'VTABLE_set_pmc_keyed_str' on the namespace object. Inside
 'set_pmc_keyed_str' in NameSpace is the logic that decides whether to
 store a sub in the namespace, or in the cache of methods/vtable overrides
 associated with the namespace, or directly in the class if there is one
 associated with the namespace.)

 The right fix is to change 'set_pmc_keyed_str' in NameSpace so that it
 stores methods () by calling the 'add_to_class' function, and skipping the
 code that stores the method in the namespace. Method objects are
 identifiable because they are sub objects marked with the
 SUB_COMP_FLAG_METHOD flag in 'sub->comp_flags'. The 'add_to_class'
 function calls 'add_method' on the class object when there is one, and
 stores the method in a special hash for methods inside the namespace
 object when the class object doesn't exist yet. With the current code in
 'set_pmc_keyed_str' in NameSpace, it's very difficult to store the sub in
 the class and skip storing it in the namespace. The code badly needs a
 cleanup and refactor into subroutines.

 Throw away the nsentry2 branch and start over (it's a pretty lightweight
 branch anyway, mostly test changes adding :nsentry where it shouldn't be
 needed).

 Please write a set of tests to go with any fixes for this feature that
 make sure:

  * :method alone stores the sub in the class but not in the namespace
 (this means the sub object can be called as a method but not as a sub)
  * :method with :nsentry stores the sub in the class and in the namespace
 (this means the sub object can be called as either a method or a sub)
  * :vtable alone stores the sub in the class but not in the namespace
  * :vtable with :nsentry stores the sub in the class and in the namespace
  * that both options work with :multi
  * that regular subs are still stored appropriately in the namespace (and
 can be called as a sub, but not as a method or vtable override)

-- 
Ticket URL: <https://trac.parrot.org/parrot/ticket/389#comment:17>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development
_______________________________________________
parrot-tickets mailing list
[email protected]
http://lists.parrot.org/mailman/listinfo/parrot-tickets

Reply via email to