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

Rakudo can't handle A declared after A::B was declared in an included module #666

Closed
p6rt opened this issue Jan 29, 2009 · 10 comments
Closed

Comments

@p6rt
Copy link

p6rt commented Jan 29, 2009

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

Searchable as RT62898$

@p6rt
Copy link
Author

p6rt commented Jan 29, 2009

From @masak

In Rakudo r36143, the following works​:

$ perl6 -e 'role A​::B {}; class A {}' # works

But put the role declaration in its own module file A/B.pm​:

$ cat A/B.pm
use v6;
role A​::B {
}
$ perl6 -e 'use A​::B; class A {}' # fails
Re-declaration of type A at line 1, near ""
[...]

The problem is somehow tied to 'use', becuase this works​:

$ perl6 -e 'role A​::B {}; class A {}' # works

All of the above also holds when A​::B is declared as being a class,
but things work when A is declared as being a role.

@p6rt
Copy link
Author

p6rt commented Feb 7, 2009

From @chrisdolan

Consider the following two files​:

--- Foo/Bar/Baz.pm ---
class Foo​::Bar​::Baz {
}

--- Foo/Bar.pm ---
use Foo​::Bar​::Baz;
class Foo​::Bar {
}

When you load Foo​::Bar, you get​:
  Re-declaration of type Foo​::Bar at line 4, near ""

I think this is because 'use'ing Foo​::Bar​::Baz vivifies the Foo​::Bar
package. This error does NOT happen if the two classes are declared
in the same file, presumably a compiletime-vs-runtime difference.

This problem began sometime in the last month.

@p6rt
Copy link
Author

p6rt commented Feb 8, 2009

From @chrisdolan

Ahh, It looks like my report below is a duplicate of
  [perl #​62898] Rakudo can't handle A declared after A​::B was
declared in an included module
Sorry about that...
Chris

On Feb 7, 2009, at 4​:10 PM, perl6 via RT wrote​:

Consider the following two files​:

--- Foo/Bar/Baz.pm ---
class Foo​::Bar​::Baz {
}

--- Foo/Bar.pm ---
use Foo​::Bar​::Baz;
class Foo​::Bar {
}

When you load Foo​::Bar, you get​:
Re-declaration of type Foo​::Bar at line 4, near ""

I think this is because 'use'ing Foo​::Bar​::Baz vivifies the Foo​::Bar
package. This error does NOT happen if the two classes are declared
in the same file, presumably a compiletime-vs-runtime difference.

This problem began sometime in the last month.

@p6rt
Copy link
Author

p6rt commented Feb 8, 2009

From @masak

Chris (>)​:

Ahh, It looks like my report below is a duplicate of
[perl #​62898] Rakudo can't handle A declared after A​::B was
declared in an included module
Sorry about that...

No problem. Better to over-report than to under-report. Also, nobody
faults you for not having an overview of the present list of open bugs. ;)

// Carl

@p6rt
Copy link
Author

p6rt commented Feb 8, 2009

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

@p6rt
Copy link
Author

p6rt commented Feb 8, 2009

From @chrisdolan

The following reproduces the bug more simply​:

  perl6 -e 'BEGIN {class Foo​::Bar​::Baz {}}; class Foo​::Bar {}'

I'm working on a patch at the Frozen Perl hackathon now...

@p6rt
Copy link
Author

p6rt commented Feb 8, 2009

From @chrisdolan

I wrote a simple solution that works, but I'd like someone more PIR-
savvy to improve it.

http://github.com/chrisdolan/rakudo/tree/package-redeclaration (5d6cec9)

--- a/src/parser/methods.pir
+++ b/src/parser/methods.pir
@​@​ -30,8 +30,11 @​@​ Registers a type in the namespace.
  # Check if the symbol already exists in the NS; if so we record
it as
  # an existing type.
  $P0 = get_hll_global ns, short_name
- unless null $P0 goto type_exists
+ if null $P0 goto no_namespace
+ $S0 = typeof $P0
+ unless $S0 == 'NameSpace' goto type_exists

+ no_namespace​:
  # Work outwards to find a block defining a package and put the
type
  # there. XXX This makes it too visible for lexical types, but
if we
  # assume lexical rather than package scope then we will fail
various

@p6rt
Copy link
Author

p6rt commented Feb 8, 2009

From @moritz

On Sun Feb 08 11​:42​:32 2009, chris@​chrisdolan.net wrote​:

I wrote a simple solution that works, but I'd like someone more PIR-
savvy to improve it.

http://github.com/chrisdolan/rakudo/tree/package-redeclaration (5d6cec9)

For the record, this works with this command​:
git-pull git​://github.com/chrisdolan/rakudo.git package-redeclaration
git-push

Chirs also added tests to t/spec/S12-class/basic.t, so we can close this
ticket.

Thanks for the good work,
Moritz

@p6rt
Copy link
Author

p6rt commented Feb 8, 2009

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

@p6rt
Copy link
Author

p6rt commented Feb 8, 2009

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

@p6rt p6rt closed this as completed Feb 8, 2009
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