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

Weird error in anonymous class value in Hash #6067

Open
p6rt opened this issue Feb 12, 2017 · 5 comments
Open

Weird error in anonymous class value in Hash #6067

p6rt opened this issue Feb 12, 2017 · 5 comments
Labels
Bug LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Feb 12, 2017

Migrated from rt.perl.org#130763 (status was 'open')

Searchable as RT130763$

@p6rt
Copy link
Author

p6rt commented Feb 12, 2017

From jns@gellyfish.co.uk

Hi,
I was trying to make an array of hashes which had one member an
anonymous class for some tests, so I did​:

  my @​f = %{ class => class { has Int $.attr; }, }; say @​f.perl

Which gave rise to​:

  When invoking 2 '', provided outer frame 0x2b11cb0 (4 '<unit>') does
  not match expected static frame 0x2b11db8 (3 '')
    in block <unit> at -e line 1

Which was definitely unexpected and not something I had seen before.

Naming the class gives a different errror but suggests everything
inside the outer curlies is being interpreted as a block for some
reason​:

  my @​f = %{ class => class Foo { has Int $.attr; }, }; say @​f.perl

Giving​:

  Odd number of elements found where hash initializer expected​:
  Only saw​: -> ;; $_? is raw { #`(Block|50212200) ... }
    in block <unit> at -e line 1

Inlining the class does work like that does work without the additional
curlies​:

  my %f =  class => class  { has Int $.attr; }; say %f.perl

Giving​:

  {​:class(<anon|60919760>)}

Of course what I actually meant originally was​:

  my @​f = (%( "class" => class  { has Int $.attr; }, ),); say @​f.perl

So I guess at the very least it's a LTA error message but does seem to
point to some other bug.

@p6rt
Copy link
Author

p6rt commented Feb 12, 2017

From @zoffixznet

Golfed a bit​:

<Zoffix> m​: { foo => class {} }()
<camelia> rakudo-moar 266f34​: OUTPUT«When invoking 1 '', provided outer frame 0x322f4e0 (3 '<unit>') does not match expected static frame 0x322f5e8 (2 '')␤ in block <unit> at <tmp> line 1␤␤»

@p6rt
Copy link
Author

p6rt commented Feb 12, 2017

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

@p6rt
Copy link
Author

p6rt commented Feb 12, 2017

From @timo

This is caused by the way we differentiate between anonymous blocks and
hashes; we just parse it as a block first, and if at the end it turns
out it should be a hash instead, we change it around. I suppose at that
point the class will already have been defined and its stuff will point
at the "not actually a block any more" thing that we had as a "stand-in"
when we weren't sure yet whether it should be a hash or a block ...

@p6rt p6rt added Bug LTA Less Than Awesome; typically an error message that could be better labels Jan 5, 2020
@usev6
Copy link

usev6 commented Feb 19, 2023

As a status update: The first example from the OP no longer gives a weird error:

$ ./rakudo-m -e 'my @f = %{ class => class { has Int $.attr }, }; say @f.raku'
[:class(<anon|1>)]

So an Array with a Pair as the first (and only) element is created. That looks reasonable to me.

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

No branches or pull requests

2 participants