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

-> declarations cannot immediately follow an import #104

Closed
catb0t opened this issue Aug 4, 2019 · 0 comments
Closed

-> declarations cannot immediately follow an import #104

catb0t opened this issue Aug 4, 2019 · 0 comments

Comments

@catb0t
Copy link
Contributor

catb0t commented Aug 4, 2019

module A { class X {} }
module B {
  include A

  import A::X

  -> f (x) { }
  -> g (x) { }
}

the error is

[INFO] `x` is parsed as a prefix method-call at t.sf line 7
sidef: You're embarrassing me! That's not funny!

File : t.sf
Line : 7 : 6
Error: variable <x> is not declared in the current scope

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.f (x) -> Bool { }

I think the .f in the deparsed is revealing the parser bug; it is parsed as (import ...)->f(x). That's perfectly logical but it's probably not intended.

The imported name does not have to appear anywhere; the import statement alone causes the problem.

If -> f () {} is declared without arguments, then it compiles to Perl without errors, but Perl says Bareword "f" not allowed while "strict subs" in use at (eval 8) line 138.

It behaves the same if the code is not inside a module, but in main scope (but then that requires another file to demonstrate the bug).

It works in any of these separate cases:

  • f is changed to func f (x) { } while g is still -> g, or
  • the import is removed, but the include is kept

Here's the full -Rperl output: t.pl.txt

@trizen trizen closed this as completed in 2a9e784 Aug 4, 2019
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