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

Warnings on use of undefined routine? #191

Closed
p6rt opened this issue Jul 27, 2008 · 15 comments
Closed

Warnings on use of undefined routine? #191

p6rt opened this issue Jul 27, 2008 · 15 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jul 27, 2008

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

Searchable as RT57332$

@p6rt
Copy link
Author

p6rt commented Jul 27, 2008

From @masak

$ svn info | grep Revi
Revision​: 29791

There's no problem matching against an extant class​:

$ ./perl6 -e 'class A {}; say "mm, pie" ~~ A'
0

But matching against an undefined class doesn't work​:

$ ./perl6 -e 'say "mm, pie" ~~ A'
Method 'ACCEPTS' not found for invocant of class 'Failure'
current instr.​: 'infix​:~~' pc 12501 (src/gen_builtins.pir​:7936)
called from Sub '_block11' pc 34 (EVAL_13​:17)
called from Sub 'parrot;PCT​::HLLCompiler;eval' pc 806
(src/PCT/HLLCompiler.pir​:481)
called from Sub 'parrot;PCT​::HLLCompiler;command_line' pc 1305
(src/PCT/HLLCompiler.pir​:708)
called from Sub 'parrot;Perl6​::Compiler;main' pc 14567 (perl6.pir​:172)

Now, it shouldn't work (because A hasn't been defined), but

* The error is all wrong. The class 'Failure' has got nothing to do with it.
* It feels like this could/should be intercepted at BEGIN time, just
like the `class DerivingClass is NotYetDefinedClass {}` error. In both
cases, it's a question of an undeclared bareword.

@p6rt
Copy link
Author

p6rt commented Jul 27, 2008

From @pmichaud

On Sun, Jul 27, 2008 at 07​:27​:50AM -0700, Carl Mäsak wrote​:

* The error is all wrong. The class 'Failure' has got nothing to do with it.
* It feels like this could/should be intercepted at BEGIN time, just
like the `class DerivingClass is NotYetDefinedClass {}` error. In both
cases, it's a question of an undeclared bareword.

You're correct, Rakudo doesn't maintain a compile-time symbol table
at the moment, and thus isn't detecting undeclared barewords yet.

This is a _little_ bit trickier than it might seem at first, since
Perl 6 assumes that unrecognized identifiers (barewords) can be
post-declared listops. So, BEGIN may be a little too soon -- we
may want to do it at CHECK time or something like that.

Currently most refactors having to do with BEGIN/INIT/END/etc. are
awaiting Parrot's merge of the concurrency/exceptions (pdd25cx) branch
back into trunk.

Pm

@p6rt
Copy link
Author

p6rt commented Jul 27, 2008

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

@p6rt
Copy link
Author

p6rt commented Nov 21, 2008

From @chrisdolan

If you accidentally try to instantiate a class that has not been
defined, but the namespace for that class has been vivified, then you
get an obscure error message​:

  % perl6 -e 'class Foo​::Bar​::Baz { }; Foo​::Bar.new;'
  Null PMC access in get_string()
  current instr.​: 'parrot;Perl6Object;new' pc 277 (src/
gen_builtins.pir​:190)
  called from Sub '_block11' pc 27 (EVAL_11​:17)
  called from Sub 'parrot;PCT;HLLCompiler;eval' pc 898 (src/PCT/
HLLCompiler.pir​:510)
  called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1450
(src/PCT/HLLCompiler.pir​:774)
  called from Sub 'parrot;Perl6;Compiler;main' pc 16257 (perl6.pir​:
168)

With the attached patch, Rakudo instead dies with a more informative
message​:

  % perl6 -e 'class Foo​::Bar​::Baz { }; Foo​::Bar.new;'
  Cannot instantiate Module. Perhaps you have not defined a class
named Foo​::Bar?
  current instr.​: 'die' pc 12358 (src/gen_builtins.pir​:7530)
  called from Sub 'parrot;Module;new' pc 8086 (src/
gen_builtins.pir​:5170)
  called from Sub '_block11' pc 27 (EVAL_11​:17)
  called from Sub 'parrot;PCT;HLLCompiler;eval' pc 898 (src/PCT/
HLLCompiler.pir​:510)
  called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1450
(src/PCT/HLLCompiler.pir​:774)
  called from Sub 'parrot;Perl6;Compiler;main' pc 16257 (perl6.pir​:
168)

The patch is a bit of a hack. It introduces a new() method to
Module.pir which just constructs the error message and dies. Most of
the added code is used to build the intended class name. Surely
someone more familiar with the NameSpace pmc can improve it a bit?

  Module.pir | 19 +++++++++++++++++++
  1 files changed, 19 insertions(+)

@p6rt
Copy link
Author

p6rt commented Nov 21, 2008

From @chrisdolan

undefined_class.patch
Index: languages/perl6/src/classes/Module.pir
===================================================================
--- languages/perl6/src/classes/Module.pir	(revision 32970)
+++ languages/perl6/src/classes/Module.pir	(working copy)
@@ -19,6 +19,25 @@
     p6meta.'register'('NameSpace', 'parent'=>moduleproto, 'protoobject'=>moduleproto)
 .end
 
+.sub 'new' :method
+    .local pmc name, iter
+    name = self.'get_name'()
+    iter = new 'Iterator', name
+    # Drop parrot::
+    $S0 = shift iter
+    # always have at least one part
+    $S0 = shift iter
+  name_loop:
+    unless iter goto name_end
+    $S1 = shift iter
+    $S0 = concat $S0, '::'
+    $S0 = concat $S0, $S1
+    goto name_loop
+  name_end:
+     $S0 = concat 'Cannot instantiate Module.  Perhaps you have not defined a class named ', $S0
+     $S0 = concat $S0, '?'
+    'die'($S0)
+.end
 
 =head1 METHODS
 

@p6rt
Copy link
Author

p6rt commented Nov 21, 2008

From @chrisdolan

There is at least one problem with the approach in this patch. I now get​:

% perl6 -e 'my %h = :a(1); %h.pairs'
Cannot instantiate Module. Perhaps you have not defined a class named
Perl6Pair?

@p6rt
Copy link
Author

p6rt commented Nov 26, 2008

From @jnthn

On Thu Nov 20 20​:46​:18 2008, chris@​chrisdolan.net wrote​:

If you accidentally try to instantiate a class that has not been
defined, but the namespace for that class has been vivified, then you
get an obscure error message​:
...
With the attached patch, Rakudo instead dies with a more informative
message​:
...
The patch is a bit of a hack. It introduces a new() method to
Module.pir which just constructs the error message and dies. Most of
the added code is used to build the intended class name. Surely
someone more familiar with the NameSpace pmc can improve it a bit?

We should actually detect this at compile time, not runtime. That
depends on registering and checking/looking up symbols as we compile,
which is on the task list for the next month or so. So thanks for the
patch, but I'm afraid it's the wrong approach.

I will leave the ticket open, however, as something that needs to happen
as a result of the symbol registry stuff. Once we get a useful error
message at compile time, it's can be closed.

Thanks!

Jonathan

@p6rt
Copy link
Author

p6rt commented Nov 26, 2008

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

@p6rt
Copy link
Author

p6rt commented Nov 27, 2008

From @chrisdolan

On Wed Nov 26 12​:38​:19 2008, jnthn@​jnthn.net wrote​:

We should actually detect this at compile time, not runtime. That
depends on registering and checking/looking up symbols as we compile,
which is on the task list for the next month or so. So thanks for the
patch, but I'm afraid it's the wrong approach.

I will leave the ticket open, however, as something that needs to happen
as a result of the symbol registry stuff. Once we get a useful error
message at compile time, it's can be closed.

Thanks!

Jonathan

Yes, I agree the patch is a terrible approach. I'll change the subject
to [TODO] and mark it stalled

@p6rt
Copy link
Author

p6rt commented Jan 26, 2009

From @masak

This now works in r35994​:

$ perl6 -e 'say "mm, pie" ~~ A'
Could not find non-existent sub A
[...]

Not sure if I can resolve the ticket though, since things are still not
checked before runtime​:

$ perl6 -e 'say "OH HAI"; say "mm, pie" ~~ A'
OH HAI
Could not find non-existent sub A
[...]

@p6rt
Copy link
Author

p6rt commented Jan 28, 2009

From @jnthn

On Mon Jan 26 02​:42​:39 2009, masak wrote​:

This now works in r35994​:

$ perl6 -e 'say "mm, pie" ~~ A'
Could not find non-existent sub A
[...]

Not sure if I can resolve the ticket though, since things are still not
checked before runtime​:

$ perl6 -e 'say "OH HAI"; say "mm, pie" ~~ A'
OH HAI
Could not find non-existent sub A
[...]

Since A could well be a post-declared listop, maybe we can warn about A
being an undefined routine, but I think that is the most we can do at
compile time (so it's a warning not an error). Thoughts?

Jonathan

@p6rt
Copy link
Author

p6rt commented Jan 28, 2009

From @jnthn

Merged a couple of tickets together that basically boil down to the same
thing - when you write something you expect to be a type name, but it
gets (correctly) treated as a call to a routine, but that isn't quite
what we want...

@p6rt
Copy link
Author

p6rt commented Jan 28, 2009

From @jnthn

On Wed Jan 28 08​:02​:22 2009, jnthn@​jnthn.net wrote​:

Merged a couple of tickets together that basically boil down to the same
thing - when you write something you expect to be a type name, but it
gets (correctly) treated as a call to a routine, but that isn't quite
what we want...

Or at least, we want it to at least warn, maybe...comments welcome.

@p6rt
Copy link
Author

p6rt commented Oct 16, 2011

From @moritz

Now dies at CHECK time​:

./perl6 -e 'say "mm, pie" ~~ A'
===SORRY!===
CHECK FAILED​:
Undefined routine '&A' called (line 1)

I think that's good enough to close this ticket (tested in
t/spec/integration/error-reporting.t)

@p6rt
Copy link
Author

p6rt commented Oct 16, 2011

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

@p6rt p6rt closed this as completed Oct 16, 2011
@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant