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

Error message when using a term bareword as if it were a subroutine #6393

Open
p6rt opened this issue Jul 15, 2017 · 3 comments
Open

Error message when using a term bareword as if it were a subroutine #6393

p6rt opened this issue Jul 15, 2017 · 3 comments
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Jul 15, 2017

Migrated from rt.perl.org#131754 (status was 'new')

Searchable as RT131754$

@p6rt
Copy link
Author

p6rt commented Jul 15, 2017

From @smls

A more helpful error message than just the generic "Two terms in a row"
could be thrown when the user writes e.g.

  foo 42;

as if `foo` were a subroutine, but it's actually some other kind of
bareword such as​:

* a constant - `constant foo = ...`
* a sigilless variable - `my \foo = ...`
* a typename - `class foo { ... }`
* a label - `foo​: ...`
* a term - `sub term​:<foo> { ... }`

The error message could be expanded like this​:

  ===SORRY!=== Error while compiling [...]
  Two terms in a row
  at [...]
  ------> say foo⏏ 42;
  Note​: "foo" is not a subroutine, but a constant declared at [...].

Or in the special case that there actually *is* a subroutine with the
same name in any parent scope (including CORE​::), but it's clobbered by
the other bareword​:

  ===SORRY!=== Error while compiling [...]
  Two terms in a row
  at [...]
  ------> say foo⏏ 4;
  Note​: "foo" here does not refer to the subroutine declared
  at [...], but to the constant declared at [...].

If the sub is declared inside the setting, the phrase "the subroutine
declared at [...]" could be replaced with "the built-in subroutine".

@p6rt
Copy link
Author

p6rt commented Jul 15, 2017

From @smls

A possibly better way to phrase it​:

  ===SORRY!=== Error while compiling [...]
  Constant "foo" is followed by another term at [...]
  ------> say foo⏏ 4;
  If your meant to refer to the subroutine "foo" declared at [...],
  then either​:
  * Use `foo(...)` to disambiguate.
  * Rename the constant declared at [...] to not clobber the
  subroutine's name.

@p6rt p6rt added the LTA Less Than Awesome; typically an error message that could be better label Jan 5, 2020
@AlexDaniel
Copy link
Member

Hmmm… wouldn't it make things more complicated?

Currently:

perl6 -e 'constant foo = 99; foo 42'
===SORRY!=== Error while compiling -e
Two terms in a row
at -e:1
------> constant foo = 99; foo⏏ 42
    expecting any of:
        infix
        infix stopper
        statement end
        statement modifier
        statement modifier loop

The error message is 100% correct. But if we start changing it… what are we doing it for? So if the user:

  1. declared a constant or something else
  2. then for some reason assumed that a sub with that same name exists?

How common is this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

2 participants