Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix Foo::Bar regression

  • Loading branch information...
commit 0fa6f238de9f56f93402d47a1d4b7f09e0f31f14 1 parent b45b211
@sorear authored
Showing with 85 additions and 64 deletions.
  1. +25 −1 src/CSharpBackend.pm
  2. +34 −1 test.pl
  3. +26 −62 test2.pl
View
26 src/CSharpBackend.pm
@@ -5,6 +5,8 @@ use utf8;
package CSharpBackend;
+use Scalar::Util 'blessed';
+
# Input: A Metamodel::Unit object
# Output: A CodeGenUnit object
@@ -84,6 +86,7 @@ EOM
$_->visit_local_packages(\&pkg2);
$_->visit_local_subs_preorder(\&sub2);
+ $unit->visit_local_stashes(\&stash3) if $_ == $unit;
$_->visit_local_packages(\&pkg3);
$_->visit_local_subs_preorder(\&sub3);
@@ -131,6 +134,28 @@ sub stash2 {
}
}
+sub stash3 {
+ my $p = $lpeers{$_};
+ for my $k (sort keys %{ $_->zyg }) {
+ my $ch = $_->zyg->{$k};
+ my $bit;
+
+ if (blessed($ch)) {
+ $bit = CgOp::newscalar(CgOp::rawsget($lpeers{$ch}));
+ } else {
+ my $chd = $unit->deref($ch);
+ if ($chd->isa('Metamodel::Package') &&
+ defined $chd->{peer}{what_var}) {
+ $bit = CgOp::rawsget($chd->{peer}{what_var});
+ }
+ }
+
+ next unless $bit;
+ push @thaw, CgOp::bset(CgOp::rawscall('Kernel.PackageLookup',
+ CgOp::rawsget($p), CgOp::clr_string($k)), $bit);
+ }
+}
+
# xxx check for SAFE::
my %loopbacks = (
'MAny', 'Kernel.AnyMO',
@@ -138,7 +163,6 @@ my %loopbacks = (
'MGatherIterator', 'RxFrame.GatherIteratorMO',
'MList', 'RxFrame.ListMO',
'MMatch', 'RxFrame.MatchMO',
- 'PStash', 'Kernel.StashP',
'PAny', 'Kernel.AnyP',
'PArray', 'Kernel.ArrayP',
'PEMPTY', 'RxFrame.EMPTYP',
View
35 test.pl
@@ -2,7 +2,7 @@
use Test;
-plan 520;
+plan 533;
ok 1, "one is true";
ok 2, "two is also true";
@@ -1036,3 +1036,36 @@
rxtest /^ [x**2] $/, 'x**2', ('xx',), ('x','xxx');
rxtest /^ [x**y] $/, 'x**y', ('x','xyx','xyxyx'), ('','xy','yx');
}
+
+{
+ my $x;
+ (class { method foo() {
+ $x = 1;
+ } }).foo;
+ ok $x, "changes made in the protolexpad are visible at runtime";
+}
+
+{
+ my $x;
+ my $unclonable-sub = (class { method foo() { sub () { $x } } }).foo;
+ $x = 42;
+ ok $unclonable-sub() == 42, "mainlines are not cloned";
+}
+
+{
+ class Foo {
+ method foo() { 42 }
+ class Bar {
+ method bar() { 51 }
+ }
+ ok Bar.bar == 51, "within Foo, Bar is directly accessible";
+ ok OUR::Bar.bar == 51, "within Foo, Bar is package accessible";
+ ok Foo::Bar.bar == 51, "within Foo, Bar is longname accessible";
+ ok GLOBAL::Foo::Bar.bar == 51, "within Foo, Bar is GLOBAL accessible";
+ }
+ ok Foo eq 'Foo()', "lexical lookup of our-class works";
+ ok OUR::Foo eq 'Foo()', "also visible in ourpad";
+ ok GLOBAL::Foo eq 'Foo()', "also visible globally";
+ ok Foo::Bar.bar == 51, "can call through nested methods";
+ ok GLOBAL::Foo::Bar.bar == 51, "can call through GLOBAL nested";
+}
View
88 test2.pl
@@ -1,67 +1,31 @@
# vim: ft=perl6
use Test;
-{
- my $x;
- INIT {
- $x = 1;
- }
- ok $x, "changes made in the protolexpad are visible at runtime";
-}
-
-ok INIT { 1 }, "init blocks can return values";
-
-{
- my $x;
- my $unclonable-sub = INIT { sub () { $x } };
- $x = 42;
- ok $unclonable-sub() == 42, "mainlines are not cloned";
-}
-
-is $?FILE, 'test.pl', '$?FILE works';
-is $?ORIG.substr(0,5), '# vim', '$?ORIG works';
-
-{
- {
- our $x = 5; #OK
- }
- ok $::x == 5, '$::x finds our variable';
-
- package Fao { our $y = 6; } #OK
- ok $::Fao::y == 6, '$::Fao::y works as $Fao::y';
-
- { class Mao { } }
- ok ::Mao.new.defined, 'can use classes via ::Mao';
-}
-
-{
- my $x = 7; #OK
- ok $::x == 7, '$::x can find lexicals';
- class A3 {
- method moo { 42 }
- class B4 {
- ok ::A3.moo, '::A3 can find outer classes';
- }
- }
-}
-
-{
- class Foo {
- method foo() { 42 }
- class Bar {
- method bar() { 51 }
- }
- ok Bar.bar == 51, "within Foo, Bar is directly accessible";
- ok OUR::Bar.bar == 51, "within Foo, Bar is package accessible";
- ok Foo::Bar.bar == 51, "within Foo, Bar is longname accessible";
- ok GLOBAL::Foo::Bar.bar == 51, "within Foo, Bar is GLOBAL accessible";
- }
- ok Foo eq 'Foo()', "lexical lookup of our-class works";
- ok OUR::Foo eq 'Foo()', "also visible in ourpad";
- ok GLOBAL::Foo eq 'Foo()', "also visible globally";
- ok Foo::Bar.bar == 51, "can call through nested methods";
- ok GLOBAL::Foo::Bar.bar == 51, "can call through GLOBAL nested";
-}
-
+#is $?FILE, 'test.pl', '$?FILE works';
+#is $?ORIG.substr(0,5), '# vim', '$?ORIG works';
+
+# {
+# {
+# our $x = 5; #OK
+# }
+# ok $::x == 5, '$::x finds our variable';
+#
+# package Fao { our $y = 6; } #OK
+# ok $::Fao::y == 6, '$::Fao::y works as $Fao::y';
+#
+# { class Mao { } }
+# ok ::Mao.new.defined, 'can use classes via ::Mao';
+# }
+#
+# {
+# my $x = 7; #OK
+# ok $::x == 7, '$::x can find lexicals';
+# class A3 {
+# method moo { 42 }
+# class B4 {
+# ok ::A3.moo, '::A3 can find outer classes';
+# }
+# }
+# }
done-testing;
Please sign in to comment.
Something went wrong with that request. Please try again.