On Thu, 07 Sep 2017 14:53:44 -0700, ben-goldb...@hotmail.com wrote:
> The following code samples work as expected:
> 
> <BenGoldberg> m: use MONKEY; my $m = 'foo'; my $p = EVAL qq!role ::
> [\$value] \{ method $m \{ \$value } }!; say $p.^parameterize(42).foo;
> <+camelia> rakudo-moar e7a588: OUTPUT: «42␤»
> 
> <BenGoldberg> m: use MONKEY; constant $p = do { my $m = 'foo'; EVAL
> qq!role
> :: [\$value] \{ method $m \{ \$value } }! }; say
> $p.^parameterize(42).foo
> <camelia> rakudo-moar e7a588: OUTPUT: «42␤»
> 
> <BenGoldberg> m: use MONKEY; constant p = do { my $m = 'foo'; EVAL
> qq!role
> :: [\$value] \{ method $m \{ \$value } }! }; say p[42].foo
> <camelia> rakudo-moar e7a588: OUTPUT: «42␤»
> 
> The following, slightly different code samples do not work as
> expected:
> 
> m: use MONKEY; my $m = 'foo'; my $p = EVAL qq!role :: [\$value] \{
> method $m
> \{ \$value } }!; say $p[42].foo;
> <+camelia> rakudo-moar e7a588: OUTPUT: «Could not instantiate role
> '<anon|67928256>':␤Too few positionals passed; expected 2 arguments
> but got
> 1␤  in any protect at gen/moar/stage2/NQPCORE.setting line 1033␤  in
> block
> <unit> at <tmp> line 1␤␤»
> 
> <BenGoldberg> m: use MONKEY; constant $p = do { my $m = 'foo'; EVAL
> qq!role
> :: [\$value] \{ method $m \{ \$value } }! }; say $p[42].foo
> <camelia> rakudo-moar e7a588: OUTPUT: «Could not instantiate role
> '<anon|77207648>':␤Too few positionals passed; expected 2 arguments
> but got
> 1␤  in any protect at gen/moar/stage2/NQPCORE.setting line 1033␤  in
> block
> <unit> at <tmp> line 1␤␤»
> 
> <BenGoldberg> m: use MONKEY; my \p = do { my $m = 'foo'; EVAL qq!role
> ::
> [\$value] \{ method $m \{ \$value } }! }; say p[42].foo
> <camelia> rakudo-moar e7a588: OUTPUT: «Could not instantiate role
> '<anon|81583168>':␤Too few positionals passed; expected 2 arguments
> but got
> 1␤  in any protect at gen/moar/stage2/NQPCORE.setting line 1033␤  in
> block
> <unit> at <tmp> line 1␤␤»
> 

This is expected behavior. The decision of whether we're looking at a 
parametric type or an array indexing operation is made at parse time, meaning 
it's both a syntactic decision *and* depends on knowing what we've got at 
compile time is a type. Which is precisely what you're observing.

Reply via email to