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

export trait must operate with declared package name #142

Closed
vrurg opened this issue Dec 29, 2019 · 3 comments
Closed

export trait must operate with declared package name #142

vrurg opened this issue Dec 29, 2019 · 3 comments
Assignees
Labels
language Changes to the Raku Programming Language

Comments

@vrurg
Copy link
Contributor

vrurg commented Dec 29, 2019

A simple demonstration of the problem is the following code:

unit module Foo;

class B1::C is export { }
class B2::C is export { }

then:

⇒ raku -I. -MFoo -e ''
===SORRY!=== Error while compiling /Users/vrurg/src/Raku/experiments/export/Foo.pm6 (Foo)
A symbol 'C' has already been exported
at /Users/vrurg/src/Raku/experiments/export/Foo.pm6 (Foo):4

The problem is caused by export trait using ^shortname as export name of a symbol.

@vrurg vrurg added the language Changes to the Raku Programming Language label Dec 29, 2019
@vrurg
Copy link
Contributor Author

vrurg commented Dec 29, 2019

My point of view is that the principle of least surprise dictate that the export name must be the same as user specifies it in the declaration. I.e. the example code should be equivalent to:

sub EXPORT {
    Map.new(
        'B1::C' => B1::C,
        'B2::C' => B2::C,
    )
}

Proposed solution

There is no clean way to get these names from the information available for the trait. It could of course guess the enclosing package name and subtract it from full symbol names, but that a bit cumbersome way.

I propose to take what <longname> catches in Grammar and set a dynamic var $*DECLARED_NAME to that value for is export trait. I tested this implementation path, it takes right about three lines of code.

vrurg added a commit to vrurg/rakudo that referenced this issue Dec 29, 2019
For `class A::B is export { }` the export trait would use `B::C` part
even if the class is declared inside another named package.

Solves Raku/problem-solving#142
@vrurg
Copy link
Contributor Author

vrurg commented Dec 29, 2019

Proposed solution is provided by rakudo/rakudo#3388.

UPD I thought that long names are imported correctly. Unfortunately, I was wrong. More work would be required to merge symbols properly. Still, it doesn't change the point that the issue has to be taken care of.

@vrurg
Copy link
Contributor Author

vrurg commented Dec 30, 2019

The PR is ready to merge. If there're no objections for the slightly adjusted is export semantics, then it is ready for merge.

@vrurg vrurg closed this as completed Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes to the Raku Programming Language
Projects
None yet
Development

No branches or pull requests

2 participants