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

No warning when op with same name as class accidentally used #1892

Closed
p6rt opened this issue Jun 28, 2010 · 14 comments
Closed

No warning when op with same name as class accidentally used #1892

p6rt opened this issue Jun 28, 2010 · 14 comments
Labels
LTA Less Than Awesome; typically an error message that could be better notabug testneeded

Comments

@p6rt
Copy link

p6rt commented Jun 28, 2010

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

Searchable as RT76236$

@p6rt
Copy link
Author

p6rt commented Jan 25, 2010

From publiustemp-perl6internals2@yahoo.com

This code​:

  class x {
  multi method y { self.y("void") }
  multi method y (Str $arg) { say $arg }
  }
  x.new.y("foo");
  x.new.y;

Produces this output​:

  Method 'y' not found for invocant of class 'Failure'
  in Main (file src/gen_setting.pm, line 324)

It works if I put the "x.new" code in another file and "use x". It also works if I stay in the same file and I assign x.new to a variable and call .y on the variable.

  my $x = x.new;
  $x.y("foo");
  $x.y;

It fails on both master and ng, versions 7914ca3aa2f17ced09ff0707700e638d77cd5a1f and 2db8b5e6e8a5ea1559bf2668866e12476cf416fc respectively.

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

@p6rt
Copy link
Author

p6rt commented Jan 25, 2010

From @masak

Ovid (>)​:

This code​:

class x \{
    multi method y \{ self\.y\("void"\) \}
    multi method y \(Str $arg\) \{ say $arg \}
\}
x\.new\.y\("foo"\);
x\.new\.y;

Produces this output​:

Method 'y' not found for invocant of class 'Failure'
in Main \(file src/gen\_setting\.pm, line 324\)

This is a parsing issue. (Don't ask me how I know.) Put a semicolon after
the closing brace for the class, and the problem goes away. Still a bug,
of course.

@p6rt
Copy link
Author

p6rt commented Jan 25, 2010

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

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @bbkr

[13​:24] <moritz_> bbkr​: spec says that after a } either a newline or a ; is
required

# this code parses on Rakudo
class X { has Int $.id; method BUILD { $.id = 666 } } X.new

# but it's not valid according to STD
[13​:24] <moritz_> std​: class X { has Int $.id; method BUILD { $.id = 666 } }
X.new
[13​:24] <p6eval> std 31481​: OUTPUT«�[31m===�[0mSORRY!�[31m===�[0mâ�¤Method call
found where infix expected (omit whitespace?) at /tmp/KVuVqGABwZ line
1​:â�¤------> �[32mnt $.id; method BUILD { $.id = 666 } } X�[33mâ���[31m.new�[0mâ�¤
expecting infix or meta-infixâ�¤Parse failedâ�¤FAILED 00​:01 114mâ�¤Â»

# expected
Rakudo complaint about lack of ; or \n after } in class definition

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @bbkr

[14​:40] <pmichaud> 11​:19 <bbkr> rakudo​: class X { has Int $.id; method
BUILD { $.id = 666 } } X.new
[14​:40] <pmichaud> is being parsed as &infix​:<X>(class ..., $_.new)

perl6 -e 'class ABC { } ABC.new'
===SORRY!===
Confused at line 1, near "class ABC "

Indeed. Still 'class X { } X.new' should not parse as X operator usage
(I cannot find if spec forbids class named "X").

Or there should be more awesome message about X,Q,Z operators misuse.

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

@bbkr - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

@bbkr - Status changed from 'open' to 'new'

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @bbkr

Similiar issue discussed here

http://rt.perl.org/rt3/Ticket/Display.html?id=76236
(class X {} without semicolon after definition recognized as &infix​:<X>)

maybe those tickets can be merged?

@p6rt
Copy link
Author

p6rt commented Aug 12, 2010

@coke - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 29, 2012

From @diakopter

On Mon Jun 28 06​:30​:29 2010, bbkr wrote​:

[14​:40] <pmichaud> 11​:19 <bbkr> rakudo​: class X { has Int $.id; method
BUILD { $.id = 666 } } X.new
[14​:40] <pmichaud> is being parsed as &infix​:<X>(class ..., $_.new)

perl6 -e 'class ABC { } ABC.new'
===SORRY!===
Confused at line 1, near "class ABC "

Indeed. Still 'class X { } X.new' should not parse as X operator usage
(I cannot find if spec forbids class named "X").

Or there should be more awesome message about X,Q,Z operators misuse.

this has about 2-3 other later duplicates. will maybe find/merge them
later.

@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

From @labster

TL;DR testneeded on the first half, second half notabug.

These two tickets should not have been merged, apparently. Because the original ticket, #​72338​:

labster% cat foo.pl
use v6;

  class x {
  multi method y { self.y("void"); }
  multi method y (Str $arg) { say $arg }
  }
  x.new.y("foo");
  x.new.y;
labster% perl6 foo.pl
foo
void

The above can presumably be closed with a test. But on the second issue, #​72636​:
labster% perl6 -e 'class X { } X.new'
labster% perl6 -e 'class X { } X.new.say'
Any.new
labster% perl6 -e 'class A { } A.new.say'
===SORRY!=== Error while compiling -e
Strange text after block (missing semicolon or comma?)
at -e​:1
------> class A { }� A.new.say
  expecting any of​:
  infix
...

However​:
04​:53 labster m​: say(class X { } X.new)
04​:53 camelia rakudo-moar d6430c​: OUTPUT«(X) Any.newâ�¤Â»
04​:54 labster whaaaa?ð��»
04​:54 TimToady that's not doing what it appears to be doing
04​:55 try putting a semicolon where you need one
04​:55 labster indeed. I'm playing with RT#​76236, so I expected it to do something wrong.
04​:55 synbot6 Link​: https://rt-archive.perl.org/perl6/Publâ��ic/Bug/Display.html?id=76236
04​:55 TimToady 2nd X is cross operator there
04​:56 m​: say class X {} X .new
04​:56 camelia rakudo-moar d6430c​: OUTPUT«(X) Any.newâ�¤Â»
04​:56 TimToady m​: say class Y {} X .new
04​:56 camelia rakudo-moar d6430c​: OUTPUT«(Y) Any.newâ�¤Â»
04​:57 labster so is this notabug/DIHWIDT territory?
04​:57 TimToady we never intuit ; after } except at the end of a line, where we always do
04​:57 yes, notabug
04​:57 just happens to not detect the problem this time
04​:58 it means something wonky, but it does mean something
04​:58 .oO(Code is too wonky at line 42...)
04​:59 labster We really need that feature, TimToady
05​:00 That operator you keep using, it does not mean what you think it means at line 67.
05​:08 labster m​: say( class X { has Int $.id; method BUILD { $.id = 666 } } X.new )
05​:08 camelia rakudo-moar d6430c​: OUTPUT«(X) Any.newâ�¤Â»
05​:09 TimToady Y.new would also work :)
05​:10 labster wait, is it crossing the class keyword?
05​:11 TimToady yes, with a $_.new
05​:12 TimToady er, I meant Z
05​:14 TimToady in summary, P6 has very consistent rules for use of closing braces that will surprise you if you expect inconsistency
05​:14 labster and since we're expecting an operator and not a term, we don't see X as a term.
05​:14 TimToady right

1 similar comment
@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

From @labster

TL;DR testneeded on the first half, second half notabug.

These two tickets should not have been merged, apparently. Because the original ticket, #​72338​:

labster% cat foo.pl
use v6;

  class x {
  multi method y { self.y("void"); }
  multi method y (Str $arg) { say $arg }
  }
  x.new.y("foo");
  x.new.y;
labster% perl6 foo.pl
foo
void

The above can presumably be closed with a test. But on the second issue, #​72636​:
labster% perl6 -e 'class X { } X.new'
labster% perl6 -e 'class X { } X.new.say'
Any.new
labster% perl6 -e 'class A { } A.new.say'
===SORRY!=== Error while compiling -e
Strange text after block (missing semicolon or comma?)
at -e​:1
------> class A { }� A.new.say
  expecting any of​:
  infix
...

However​:
04​:53 labster m​: say(class X { } X.new)
04​:53 camelia rakudo-moar d6430c​: OUTPUT«(X) Any.newâ�¤Â»
04​:54 labster whaaaa?ð��»
04​:54 TimToady that's not doing what it appears to be doing
04​:55 try putting a semicolon where you need one
04​:55 labster indeed. I'm playing with RT#​76236, so I expected it to do something wrong.
04​:55 synbot6 Link​: https://rt-archive.perl.org/perl6/Publâ��ic/Bug/Display.html?id=76236
04​:55 TimToady 2nd X is cross operator there
04​:56 m​: say class X {} X .new
04​:56 camelia rakudo-moar d6430c​: OUTPUT«(X) Any.newâ�¤Â»
04​:56 TimToady m​: say class Y {} X .new
04​:56 camelia rakudo-moar d6430c​: OUTPUT«(Y) Any.newâ�¤Â»
04​:57 labster so is this notabug/DIHWIDT territory?
04​:57 TimToady we never intuit ; after } except at the end of a line, where we always do
04​:57 yes, notabug
04​:57 just happens to not detect the problem this time
04​:58 it means something wonky, but it does mean something
04​:58 .oO(Code is too wonky at line 42...)
04​:59 labster We really need that feature, TimToady
05​:00 That operator you keep using, it does not mean what you think it means at line 67.
05​:08 labster m​: say( class X { has Int $.id; method BUILD { $.id = 666 } } X.new )
05​:08 camelia rakudo-moar d6430c​: OUTPUT«(X) Any.newâ�¤Â»
05​:09 TimToady Y.new would also work :)
05​:10 labster wait, is it crossing the class keyword?
05​:11 TimToady yes, with a $_.new
05​:12 TimToady er, I meant Z
05​:14 TimToady in summary, P6 has very consistent rules for use of closing braces that will surprise you if you expect inconsistency
05​:14 labster and since we're expecting an operator and not a term, we don't see X as a term.
05​:14 TimToady right

@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

From @usev6

On Tue Jun 16 22​:19​:50 2015, labster wrote​:

TL;DR testneeded on the first half, second half notabug.

There is already a (passing) test for the first half (RT #​72338) in S12-class/basic.t.

I'm going ahead and close this ticket as 'resolved'. Please re-open if you disagree with the classification 'notabug' for the second part.

@p6rt p6rt closed this as completed Jun 17, 2015
@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

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

@p6rt p6rt added LTA Less Than Awesome; typically an error message that could be better notabug testneeded labels Jan 5, 2020
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 notabug testneeded
Projects
None yet
Development

No branches or pull requests

1 participant