On Mon Nov 24 15:12:48 2008, masak wrote:
> <masak> rakudo: eval { class A { has $.x } }; say A.new(x=>5).x
> <p6eval> rakudo 33156: OUTPUT[5␤Null PMC access in
> find_method()␤current instr.: 'parrot;Perl6;Compiler;main' pc 136910
> (src/gen_actions.pir:13693)␤]
> <masak> it gives the right answer, but then decides to die on some
error! :)

Taking a look at the S04:

"(Perl 6's eval function only evaluates strings, not blocks.)"

So I think the example is wrong (it sorta worked because classes are
declared at compile time and you're declaring a package class inside
that block; thus, even though we never invoked the block it still ended
up declaring the class; if you'd put a say in there, it wouldn't have
been run.)

So, why the odd error? In the builtins we weren't checking what was
passed to eval to a string. This led to oddness inside eval/the
compiler/somewhere - turns out if you feed in something that ain't a
string it does interesting stuff...but not until exit time! :-)

Anyway, a glance at S29 suggests the signature of eval should be:

multi eval ( Str $code, Grammar :$lang = CALLER::<$?PARSER>)

That is, we type-check it's a Str rather than coerce. So I've put in a
type check now and your example now gives a parameter type check
failure, which - unless the spec changes to say we should coerce instead
of type check - appears to be the right thing.

(Note: a spectest did do a very curious/useless use of eval, which I
ripped out...)

Thanks,

Jonathan

Reply via email to