I think this is just another example of the compile time closures problem
since EXPORT runs at compile time in during the loading module's
compilation.

https://rt.perl.org/Public/Bug/Display.html?id=128636

For an example in my own code:

https://github.com/spitsh/spitsh/blob/master/lib/Spit/Constants.pm6

I can't put that sub definition in the constant assignment because it runs
at compile time.

On Thu, Jun 8, 2017 at 2:31 AM Zoffix Znet <perl6-bugs-follo...@perl.org>
wrote:

> # New Ticket Created by  Zoffix Znet
> # Please include the string:  [perl #131528]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=131528 >
>
>
> From what I understand subs—even `only` subs—have another Sub playing the
> role of a dispatcher or whatever:
>
> m: sub foo {}.WHERE.say; &foo.WHERE.say
> rakudo-moar dbd0f8: OUTPUT: «139686084622776␤139686084191728␤»
>
> And it seems when the sub itself, instead of this "dispatcher", is used in
> sub EXPORT in a precompiled
> module that's used by another precompiled module, some wires get crossed
> over and the sub cannot be called:
>
>     m: sub foo {}.WHERE.say; &foo.WHERE.say
>     rakudo-moar dbd0f8: OUTPUT: «139686084622776␤139686084191728␤»
>
>
>     $ cat Foo.pm6
>     sub EXPORT {
>         Map.new: '&foo' => sub foo { say 42 }
>     }
>
>     $ cat Bar.pm6
>     use Foo;
>     foo
>
>     $ perl6 -I. -MFoo -e 'foo'
>     42
>
>     $ perl6 -I. -MBar -e ''
>     ===SORRY!===
>     Cannot invoke this object (REPR: Null; VMNull)
>     $
>
> Doing any of the following fixes the above bug:
>
> - adding `no precompilation` to Foo.pm6
> - adding `no precompilation` to Bar.pm6
> - instead of using the sub directly, defining it separately and using
> `&foo` as value in the Map
>

Reply via email to