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

Attributes can't be declared inside of a BEGIN eval in Rakudo #2543

Closed
p6rt opened this issue Oct 29, 2011 · 6 comments
Closed

Attributes can't be declared inside of a BEGIN eval in Rakudo #2543

p6rt opened this issue Oct 29, 2011 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Oct 29, 2011

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

Searchable as RT102478$

@p6rt
Copy link
Author

p6rt commented Oct 29, 2011

From @masak

<moritz> nom​: class A { eval 'has $.x' }; say A.new(x => 3).x
<p6eval> nom 9c6aed​: OUTPUT«===SORRY!===␤A cannot have attributes at
line 1, near ""␤»
<moritz> nom​: class A { BEGIN eval 'has $.x' }; say A.new(x => 3).x
<p6eval> nom 9c6aed​: OUTPUT«===SORRY!===␤A cannot have attributes at
line 1, near ""␤»
<moritz> why not?
<jnthn> moritz​: Probably that eval doesn't know it's in a class
definition or some such
<jnthn> moritz​: e.g. it's treated like a little bit of mainline
<jnthn> moritz​: I guess you can argue that the BEGIN case there should work
<moritz> jnthn​: but the error message knows that it's in A
<jnthn> moritz​: no, the error message is busted
<jnthn> The first case should certainly not work
<jnthn> The second one...maybe.
<jnthn> So the question is...
<jnthn> In eval, what do we treat as the current package?
<jnthn> masak​: The "A" in the error messsage is not referring to the clas A
<jnthn> Call it B in the code to see :)
<masak> jnthn​: aha, it's an article ;)
<jnthn> nom​: class B { BEGIN eval 'has $.x' }
<p6eval> nom 9c6aed​: OUTPUT«===SORRY!===␤A cannot have attributes at
line 1, near ""␤»
<jnthn> See the double space? :)
<jnthn> It doesn't know what sort of thing it is in :)
<jnthn> nom​: has $.x
<p6eval> nom 9c6aed​: OUTPUT«===SORRY!===␤A cannot have attributes at
line 1, near ""␤»
<jnthn> Right. :)
<jnthn> eval is doing the wrong kind of thing about current package.
* masak submits rakudobug
<jnthn> Yeah, we should probably make that one work.
<jnthn> I'm in the middle of re-doing the repr API at the moment
though, so won't get to that for a day or two.

@p6rt
Copy link
Author

p6rt commented Feb 24, 2014

From @coke

On Sat Oct 29 13​:09​:29 2011, masak wrote​:

<moritz> nom​: class A { eval 'has $.x' }; say A.new(x => 3).x
<p6eval> nom 9c6aed​: OUTPUT«===SORRY!===␤A cannot have attributes at
line 1, near ""␤»
<moritz> nom​: class A { BEGIN eval 'has $.x' }; say A.new(x => 3).x
<p6eval> nom 9c6aed​: OUTPUT«===SORRY!===␤A cannot have attributes at
line 1, near ""␤»
<moritz> why not?
<jnthn> moritz​: Probably that eval doesn't know it's in a class
definition or some such
<jnthn> moritz​: e.g. it's treated like a little bit of mainline
<jnthn> moritz​: I guess you can argue that the BEGIN case there should work
<moritz> jnthn​: but the error message knows that it's in A
<jnthn> moritz​: no, the error message is busted
<jnthn> The first case should certainly not work
<jnthn> The second one...maybe.
<jnthn> So the question is...
<jnthn> In eval, what do we treat as the current package?
<jnthn> masak​: The "A" in the error messsage is not referring to the clas A
<jnthn> Call it B in the code to see :)
<masak> jnthn​: aha, it's an article ;)
<jnthn> nom​: class B { BEGIN eval 'has $.x' }
<p6eval> nom 9c6aed​: OUTPUT«===SORRY!===␤A cannot have attributes at
line 1, near ""␤»
<jnthn> See the double space? :)
<jnthn> It doesn't know what sort of thing it is in :)
<jnthn> nom​: has $.x
<p6eval> nom 9c6aed​: OUTPUT«===SORRY!===␤A cannot have attributes at
line 1, near ""␤»
<jnthn> Right. :)
<jnthn> eval is doing the wrong kind of thing about current package.
* masak submits rakudobug
<jnthn> Yeah, we should probably make that one work.
<jnthn> I'm in the middle of re-doing the repr API at the moment
though, so won't get to that for a day or two.

Behavior has changed a bit.

This now gives an awesome error and can be closed with tests​:

03​:16 < [Coke]> nom​: has $.x
03​:17 <+camelia> rakudo-parrot e8cea1, rakudo-jvm e8cea1, rakudo-moar e8cea1​:
  OUTPUT«===SORRY!=== Error while compiling /tmp/tmpfile␤You
  cannot declare attribute '$.x' here; maybe you'd like a class
  or a role?␤at /tmp/tmpfile​:1␤------> has $.x⏏<EOL>␤ …»

However, the examples from earlier now give errors about non-rakudo objects, or methods we weren't asking about, e.g.​:

03​:16 < [Coke]> nom​: class A { BEGIN EVAL 'has $.x' }; say A.new(x => 3).x
03​:16 <+camelia> rakudo-jvm e8cea1​: OUTPUT«(timeout)»
03​:16 <+camelia> ..rakudo-parrot e8cea1​: OUTPUT«===SORRY!===␤No such method
  'name' for invocant of type 'NQPMu'␤»
03​:16 <+camelia> ..rakudo-moar e8cea1​: OUTPUT«===SORRY!===␤Cannot find method
  'name'␤»

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Feb 24, 2014

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

@p6rt
Copy link
Author

p6rt commented Oct 25, 2014

From @usev6

All of this looks good now (results are identical on Moar, Parrot and JVM)​:

$ perl6 -e 'has $.x'
===SORRY!=== Error while compiling -e
You cannot declare attribute '$.x' here; maybe you'd like a class or a role?
at -e​:1
------> has $.x⏏<EOL>
  expecting any of​:
  scoped declarator
  constraint

$ perl6 -e 'class A { BEGIN EVAL q[has $.x] }; say A.new(x => 3).x'
3

$ perl6-m -e 'class A { EVAL q[has $.x] }; say A.new(x => 3).x'
No such method 'x' for invocant of type 'A'
  in block <unit> at -e​:1

I added tests to S12-attributes/undeclared.t and S12-attributes/class.t with commit Raku/roast@7f8180122c

I'm closing this ticket now.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 25, 2014

From @usev6

All of this looks good now (results are identical on Moar, Parrot and JVM)​:

$ perl6 -e 'has $.x'
===SORRY!=== Error while compiling -e
You cannot declare attribute '$.x' here; maybe you'd like a class or a role?
at -e​:1
------> has $.x⏏<EOL>
  expecting any of​:
  scoped declarator
  constraint

$ perl6 -e 'class A { BEGIN EVAL q[has $.x] }; say A.new(x => 3).x'
3

$ perl6-m -e 'class A { EVAL q[has $.x] }; say A.new(x => 3).x'
No such method 'x' for invocant of type 'A'
  in block <unit> at -e​:1

I added tests to S12-attributes/undeclared.t and S12-attributes/class.t with commit Raku/roast@7f8180122c

I'm closing this ticket now.

@p6rt
Copy link
Author

p6rt commented Oct 25, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant