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

"nom regression" behavior of lexicals/invoking sub before they are defined changed #3454

Closed
p6rt opened this issue Jul 20, 2014 · 7 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Jul 20, 2014

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

Searchable as RT122346$

@p6rt
Copy link
Author

p6rt commented Jul 20, 2014

From @coke

S02-names-vars/variables-and-packages.t has several TODO'd tests of this sort​:

{
  nok foo().defined, "get variable not yet declared using a sub (1)";
  is foo(), 1, "get variable not yet declared using a sub (2)";
  is foo(), 2, "get variable not yet declared using a sub (3)";

  my $a;
  sub foo { $a++ }
}

Where the expectation is that the first call to the foo will return an
undefined value; in nom, it returns 0.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Aug 23, 2016

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

@p6rt
Copy link
Author

p6rt commented Aug 23, 2016

From @coke

On Sun Jul 20 10​:33​:13 2014, coke wrote​:

S02-names-vars/variables-and-packages.t has several TODO'd tests of
this sort​:

{
nok foo().defined, "get variable not yet declared using a sub (1)";
is foo(), 1, "get variable not yet declared using a sub (2)";
is foo(), 2, "get variable not yet declared using a sub (3)";

my $a;
sub foo { $a++ }
}

Where the expectation is that the first call to the foo will return an
undefined value; in nom, it returns 0.

This behavior has been in place for years now, since before Christmas.

Tagging [@​LARRY] to get a ruling on whether the test is any good.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Aug 23, 2016

From @zoffixznet

The behaviour can be demonstrated without involving subs​:

  my $a; dd $a++
  # OUTPUT​:
  # 0

And this behaviour is desired in, for example, this construct​:

  loop { last if $++ > 42 }

Whereas I can't think of a usecase where it would be useful to return an Any type object on the first ++ that would trigger warnings in the example above.

So IMO the test is bogus as it expects behaviour that's undesirable.

@p6rt
Copy link
Author

p6rt commented Aug 23, 2016

From @pmichaud

On Tue, Aug 23, 2016 at 10​:28​:26AM -0700, Will Coleda via RT wrote​:

Where the expectation is that the first call to the foo will return an
undefined value; in nom, it returns 0.

This behavior has been in place for years now, since before Christmas.

Tagging [@​LARRY] to get a ruling on whether the test is any good.

The relevant (offending?) line in the source code is https://github.com/rakudo/rakudo/blob/nom/src/core/Any.pm#L444 :

  multi postfix​:<++>(Mu​:U $a is rw) { $a = 1; 0 }

Pm

@p6rt
Copy link
Author

p6rt commented Jun 4, 2017

From @zoffixznet

On Sun, 20 Jul 2014 10​:33​:13 -0700, coke wrote​:

S02-names-vars/variables-and-packages.t has several TODO'd tests of
this sort​:

{
nok foo().defined, "get variable not yet declared using a sub (1)";
is foo(), 1, "get variable not yet declared using a sub (2)";
is foo(), 2, "get variable not yet declared using a sub (3)";

my $a;
sub foo { $a++ }
}

Where the expectation is that the first call to the foo will return an
undefined value; in nom, it returns 0.

I reworded the fudges[^1] to test for current behaviour, which IMO is
massively more desirable that to issue warnings any time you numericly
compare a post-incremented anon state var.

[1] Raku/roast@65a0dc5db3

@p6rt
Copy link
Author

p6rt commented Jun 4, 2017

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

@p6rt p6rt closed this as completed Jun 4, 2017
@p6rt p6rt added the at_larry 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