Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exported subs from imported modules affect imported modules downstream in Rakudo #1000

Closed
p6rt opened this issue May 17, 2009 · 5 comments
Closed

Comments

@p6rt
Copy link

p6rt commented May 17, 2009

Migrated from rt.perl.org#65738 (status was 'resolved')

Searchable as RT65738$

@p6rt
Copy link
Author

p6rt commented May 17, 2009

From @masak

<masak> I've asked this before, but gotten contradictory answers​: if
I'm in a script and import modules A and B, and A exports a bunch of
subs which override Perl 6 core subs, will these still be overriddent
in module B?
<moritz_> masak​: no.
<moritz_> masak​: B unly sees the overridden symbols if it uses lift
<masak> moritz_​: among the two possible answers, that's the one I like.
<JDlugosz> masak​: no. In Perl 5, the override is lexical. In Perl
6, it should be the same.
<masak> moritz_​: I've actually been bitten by Rakudo implementing the
other answer. :/
<moritz_> masak​: then do your job (and rt it) ;-)
<masak> moritz_​: yes.

$ cat A.pm
sub print(*@​args) is export(​:DEFAULT) {
  say "I'm in ur module, overriding ur functions!";
}
$ cat B.pm
print "OH HAI"
$ perl6 -e 'use A; use B'
I'm in ur module, overriding ur functions!

Finally, getting some support from S11​: "It must be possible for any
official module to be separately compiled without knowledge of the
context in which it will be embedded, and this separate compilation
must be able to produce a deterministic profile of the interface."

@p6rt
Copy link
Author

p6rt commented Apr 24, 2010

From @jnthn

On Sun May 17 11​:57​:26 2009, masak wrote​:

$ cat A.pm
sub print(*@​args) is export(​:DEFAULT) {
say "I'm in ur module, overriding ur functions!";
}
$ cat B.pm
print "OH HAI"
$ perl6 -e 'use A; use B'
I'm in ur module, overriding ur functions!

Finally, getting some support from S11​: "It must be possible for any
official module to be separately compiled without knowledge of the
context in which it will be embedded, and this separate compilation
must be able to produce a deterministic profile of the interface."

This is probably fixed since we implemented lexical import. On latest
Rakudo​:

C​:\Consulting\rakudo>type A.pm
sub print(*@​args) is export(​:DEFAULT) {
  say "I'm in ur module, overriding ur functions!";
}

C​:\Consulting\rakudo>type B.pm
print "OH HAI";

C​:\Consulting\rakudo>perl6 -e "use A; use B;"
OH HAI

So, seems fine now. :-) Given to moritz++ for spectests.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Apr 24, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 8, 2010

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 8, 2010
@p6rt
Copy link
Author

p6rt commented May 8, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in at least one of these files​: t/spec/S10-packages/basic.t, t/spec/packages/Foo.pm, t/spec/packages/OverrideTest.pm

commit 7c110845fe4de348e248528161243bf60e99bfeb
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Sat May 8 09​:21​:37 2010 +0000

  [t/spec] test for RT #​65738, overriding exports do not affect modules loaded later on
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;30587 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S10-packages/basic.t b/t/spec/S10-packages/basic.t
index f1dfacf..1e1a88c 100644
--- a/t/spec/S10-packages/basic.t
+++ b/t/spec/S10-packages/basic.t
@@ -4,7 +4,7 @@ use v6;
 
 use Test;
 
-plan 51;
+plan 52;
 
 regex fairly_conclusive_platform_error {:i ^\N*<<Null?>>}
 
@@ -206,6 +206,11 @@ eval_lives_ok q' module MapTester { (1, 2, 3).map: { $_ } } ',
     eval_lives_ok 'use LoadFromInsideAClass',
         'can "use" a class inside a class';
 
+    # RT #65738
+    use Foo;
+    use OverrideTest;
+    is test_ucfirst('moin'), 'Moin',
+        'overrides from one module do not affect a module that is loaded later on';
 }
 
 {
diff --git a/t/spec/packages/Foo.pm b/t/spec/packages/Foo.pm
index 3a2edc3..85856b5 100644
--- a/t/spec/packages/Foo.pm
+++ b/t/spec/packages/Foo.pm
@@ -4,3 +4,5 @@ use v6;
 class Foo;
 
 method foo { "foo" }
+
+sub ucfirst($thing) is export(:DEFAULT) { 'overridden ucfirst' }
diff --git a/t/spec/packages/OverrideTest.pm b/t/spec/packages/OverrideTest.pm
new file mode 100644
index 0000000..fc42130
--- /dev/null
+++ b/t/spec/packages/OverrideTest.pm
@@ -0,0 +1,5 @@
+module OverrideTest {
+    sub test_ucfirst($y) is export(:DEFAULT) {
+        ucfirst($y);
+    }
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant