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

Can't implicitly numify Failure in Rakudo #1904

Open
p6rt opened this issue Jun 30, 2010 · 10 comments
Open

Can't implicitly numify Failure in Rakudo #1904

p6rt opened this issue Jun 30, 2010 · 10 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 30, 2010

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

Searchable as RT76294$

@p6rt
Copy link
Author

p6rt commented Jun 30, 2010

From @masak

<masak> rakudo​: say "abcd".index("xyz") == 0
<p6eval> rakudo aa015a​: OUTPUT«Method 'Bridge' not found for invocant
of class 'Failure' [...]
<masak> arnsholt​: possible issue :)
* masak submits rakudobug
<masak> rakudo​: Failure == 0
<p6eval> rakudo aa015a​: OUTPUT«Method 'Bridge' not found for invocant
of class [...]
* masak is not sure he likes .Bridge :/

Might be that comparing Failure (or any non-numeric type object, for
that matter) with any number should give a warning or something, but
it should not give this error.

@p6rt
Copy link
Author

p6rt commented Jul 1, 2010

From @masak

As colomon++ pointed out, this works​:

<masak> rakudo​: say +Failure
<p6eval> rakudo 7df2c2​: OUTPUT«Use of uninitialized value in numeric context␤0␤»

So it's rather any *implied* numification that fails.

@p6rt
Copy link
Author

p6rt commented Jul 1, 2010

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

@p6rt
Copy link
Author

p6rt commented Sep 20, 2011

From @coke

On Wed Jun 30 07​:48​:56 2010, masak wrote​:

<masak> rakudo​: say "abcd".index("xyz") == 0
<p6eval> rakudo aa015a​: OUTPUT�Method 'Bridge' not found for invocant
of class 'Failure' [...]
<masak> arnsholt​: possible issue :)
* masak submits rakudobug
<masak> rakudo​: Failure == 0
<p6eval> rakudo aa015a​: OUTPUT�Method 'Bridge' not found for invocant
of class [...]
* masak is not sure he likes .Bridge :/

Might be that comparing Failure (or any non-numeric type object, for
that matter) with any number should give a warning or something, but
it should not give this error.

It now warns​:

00​:43 < [Coke]> rakudo​: say "abcd".index("xyz") == 0
00​:43 <+p6eval> rakudo cbdd9b​: OUTPUT«Use of uninitialized value in numeric
  context␤Bool​::True␤»

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 21, 2012

From @coke

On Mon Sep 19 21​:43​:52 2011, coke wrote​:

On Wed Jun 30 07​:48​:56 2010, masak wrote​:

<masak> rakudo​: say "abcd".index("xyz") == 0
<p6eval> rakudo aa015a​: OUTPUT�Method 'Bridge' not found for invocant
of class 'Failure' [...]
<masak> arnsholt​: possible issue :)
* masak submits rakudobug
<masak> rakudo​: Failure == 0
<p6eval> rakudo aa015a​: OUTPUT�Method 'Bridge' not found for invocant
of class [...]
* masak is not sure he likes .Bridge :/

Might be that comparing Failure (or any non-numeric type object, for
that matter) with any number should give a warning or something, but
it should not give this error.

It now warns​:

00​:43 < [Coke]> rakudo​: say "abcd".index("xyz") == 0
00​:43 <+p6eval> rakudo cbdd9b​: OUTPUT«Use of uninitialized value in numeric
context␤Bool​::True␤»

Current behavior​:

say +Failure
Parameter '' requires an instance, but a type object was passed
say "abcd".index("xyz") == 0
Parameter '' requires an instance, but a type object was passed
Failure == 0
use of uninitialized variable $max of type Failure in numeric context
False

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Mar 16, 2015

From @usev6

Now all three commands complain about a type object being passed when an instance is required​:

$ perl6 -e 'say +Failure'
Invocant requires an instance, but a type object was passed
  in method Numeric at src/gen/m-CORE.setting​:15733
  in block <unit> at -e​:1

$ perl6 -e 'say "abcd".index("xyz") == 0'
Invocant requires an instance, but a type object was passed
  in method Bridge at src/gen/m-CORE.setting​:5603
  in sub infix​:<==> at src/gen/m-CORE.setting​:5521
  in block <unit> at -e​:1

$ perl6 -e 'Failure == 0'
Invocant requires an instance, but a type object was passed
  in method Numeric at src/gen/m-CORE.setting​:15733
  in sub infix​:<==> at src/gen/m-CORE.setting​:5323
  in block <unit> at -e​:1

Is that reasonable or what would be an adequate error message?

1 similar comment
@p6rt
Copy link
Author

p6rt commented Mar 16, 2015

From @usev6

Now all three commands complain about a type object being passed when an instance is required​:

$ perl6 -e 'say +Failure'
Invocant requires an instance, but a type object was passed
  in method Numeric at src/gen/m-CORE.setting​:15733
  in block <unit> at -e​:1

$ perl6 -e 'say "abcd".index("xyz") == 0'
Invocant requires an instance, but a type object was passed
  in method Bridge at src/gen/m-CORE.setting​:5603
  in sub infix​:<==> at src/gen/m-CORE.setting​:5521
  in block <unit> at -e​:1

$ perl6 -e 'Failure == 0'
Invocant requires an instance, but a type object was passed
  in method Numeric at src/gen/m-CORE.setting​:15733
  in sub infix​:<==> at src/gen/m-CORE.setting​:5323
  in block <unit> at -e​:1

Is that reasonable or what would be an adequate error message?

@p6rt
Copy link
Author

p6rt commented Mar 16, 2015

From @lizmat

On 16 Mar 2015, at 18​:50, Christian Bartolomaeus via RT <bugs-comment@​bugs6.perl.org> wrote​:
$ perl6 -e 'say "abcd".index("xyz") == 0'
Invocant requires an instance, but a type object was passed
in method Bridge at src/gen/m-CORE.setting​:5603
in sub infix​:<==> at src/gen/m-CORE.setting​:5521
in block <unit> at -e​:1

.index is speculated to return a StrPos object​:

"The value returned is always a C<StrPos> object. If the substring
is found, then the C<StrPos> represents the position of the first
character of the substring. If the substring is not found, a bare
C<StrPos> containing no position is returned. This prototype C<StrPos>
evaluates to false because it's really a kind of undefined value. Do not evaluate
as a number, because instead of returning -1 it will return 0 and issue
a warning.”

This would imply it should not fail, but return True *and* give a warning!

$ perl6 -e 'say +Failure'
Invocant requires an instance, but a type object was passed
in method Numeric at src/gen/m-CORE.setting​:15733
in block <unit> at -e​:1
$ perl6 -e 'Failure == 0'
Invocant requires an instance, but a type object was passed
in method Numeric at src/gen/m-CORE.setting​:15733
in sub infix​:<==> at src/gen/m-CORE.setting​:5323
in block <unit> at -e​:1

My feeling is that these should fail. Failure’s are supposed not be thrown only when being checked for definedness. Making it a number, does not meet that criterion in my opinion.

Liz

@p6rt
Copy link
Author

p6rt commented Jul 9, 2015

From @coke

On Mon Mar 16 13​:13​:35 2015, elizabeth wrote​:

On 16 Mar 2015, at 18​:50, Christian Bartolomaeus via RT <bugs-
comment@​bugs6.perl.org> wrote​:
$ perl6 -e 'say "abcd".index("xyz") == 0'
Invocant requires an instance, but a type object was passed
in method Bridge at src/gen/m-CORE.setting​:5603
in sub infix​:<==> at src/gen/m-CORE.setting​:5521
in block <unit> at -e​:1

.index is speculated to return a StrPos object​:

"The value returned is always a C<StrPos> object. If the substring
is found, then the C<StrPos> represents the position of the first
character of the substring. If the substring is not found, a bare
C<StrPos> containing no position is returned. This prototype
C<StrPos>
evaluates to false because it's really a kind of undefined value. Do
not evaluate
as a number, because instead of returning -1 it will return 0 and
issue
a warning.”

This would imply it should not fail, but return True *and* give a
warning!

$ perl6 -e 'say +Failure'
Invocant requires an instance, but a type object was passed
in method Numeric at src/gen/m-CORE.setting​:15733
in block <unit> at -e​:1
$ perl6 -e 'Failure == 0'
Invocant requires an instance, but a type object was passed
in method Numeric at src/gen/m-CORE.setting​:15733
in sub infix​:<==> at src/gen/m-CORE.setting​:5323
in block <unit> at -e​:1

My feeling is that these should fail. Failure’s are supposed not be
thrown only when being checked for definedness. Making it a number,
does not meet that criterion in my opinion.

Liz

StrPos is gone from the design docs, so this needs to be revisited.

--
Will "Coke" Coleda

@p6rt p6rt added the Bug label Jan 5, 2020
@JJ
Copy link

JJ commented Dec 29, 2020

It's now a warning:

Use of Nil in numeric context
  in block <unit> at -e line 1
True

Which is thrown by Nil:
https://github.com/rakudo/rakudo/blob/029094282ce1f7ea032f08e85836daddd1a9e239/src/core.c/Nil.pm6#L4

So I would say this issue is solved now.

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

2 participants