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

there's no match for Any aka /./ codegens differently from m/./ #5890

Open
p6rt opened this issue Dec 16, 2016 · 5 comments
Open

there's no match for Any aka /./ codegens differently from m/./ #5890

p6rt opened this issue Dec 16, 2016 · 5 comments
Labels

Comments

@p6rt
Copy link

@p6rt p6rt commented Dec 16, 2016

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

Searchable as RT130363$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Dec 16, 2016

From @lizmat

$ 6 'm/./; dd $/'
No such method 'match' for invocant of type ‘Any'

$ 6 '/./; dd $/'
Nil $/ = Nil

Apparently the codegen of m/./ introduces a call to .match, whereas /./ codegens to something that does *not* call .match. I can only assume that’ because it assumes there can be named parameters (even though we could see that that is not the case).

So fixing the codegen in this case would not solve this problem​:

$ 6 'm​:2nd/./; dd $/'
No such method 'match' for invocant of type ‘Any'

The only way I see we could fix this, is by adding an Any.match or a Mu.match, that would just set $/ to Nil.

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Dec 19, 2016

From @lizmat

Fixed with 3fe5893 , tests needed.

On 16 Dec 2016, at 22​:14, Elizabeth Mattijsen (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Elizabeth Mattijsen
# Please include the string​: [perl #​130363]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130363 >

$ 6 'm/./; dd $/'
No such method 'match' for invocant of type ‘Any'

$ 6 '/./; dd $/'
Nil $/ = Nil

Apparently the codegen of m/./ introduces a call to .match, whereas /./ codegens to something that does *not* call .match. I can only assume that’ because it assumes there can be named parameters (even though we could see that that is not the case).

So fixing the codegen in this case would not solve this problem​:

$ 6 'm​:2nd/./; dd $/'
No such method 'match' for invocant of type ‘Any'

The only way I see we could fix this, is by adding an Any.match or a Mu.match, that would just set $/ to Nil.

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Oct 15, 2017

From @zoffixznet

On Mon, 19 Dec 2016 11​:39​:54 -0800, elizabeth wrote​:

Fixed with 3fe5893 , tests needed.

On 16 Dec 2016, at 22​:14, Elizabeth Mattijsen (via RT) <perl6-bugs-
followup@​perl.org> wrote​:

# New Ticket Created by Elizabeth Mattijsen
# Please include the string​: [perl #​130363]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130363 >

$ 6 'm/./; dd $/'
No such method 'match' for invocant of type ‘Any'

$ 6 '/./; dd $/'
Nil $/ = Nil

Apparently the codegen of m/./ introduces a call to .match, whereas
/./ codegens to something that does *not* call .match. I can only
assume that’ because it assumes there can be named parameters (even
though we could see that that is not the case).

So fixing the codegen in this case would not solve this problem​:

$ 6 'm​:2nd/./; dd $/'
No such method 'match' for invocant of type ‘Any'

The only way I see we could fix this, is by adding an Any.match or a
Mu.match, that would just set $/ to Nil.

I'm 10 months late to the party, but this looks off to me.

The commit adds a `.match` method that does nothing to virtually every object.
The listed reasoning is that `m/./` codegens differently than `/./` but
that's still the case​: `/./` constructs a Regex object (and in non-Bool context
no match against $_ is done), while `m/./` performs a match with $_, so it
wasn't surprising that `m/./` would complain about "no .match on Any",
while `/./` didn't.

Seems the new behaviour simply hides a bug in user's code, so I'm hesitant
to add it as a requirement to the language spec.

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Oct 15, 2017

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

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Oct 15, 2017

From @zoffixznet

On Sun, 15 Oct 2017 00​:12​:18 -0700, cpan@​zoffix.com wrote​:

On Mon, 19 Dec 2016 11​:39​:54 -0800, elizabeth wrote​:

Fixed with 3fe5893 , tests needed.

On 16 Dec 2016, at 22​:14, Elizabeth Mattijsen (via RT) <perl6-bugs-
followup@​perl.org> wrote​:

# New Ticket Created by Elizabeth Mattijsen
# Please include the string​: [perl #​130363]
# in the subject line of all future correspondence about this
issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130363 >

$ 6 'm/./; dd $/'
No such method 'match' for invocant of type ‘Any'

$ 6 '/./; dd $/'
Nil $/ = Nil

Apparently the codegen of m/./ introduces a call to .match, whereas
/./ codegens to something that does *not* call .match. I can only
assume that’ because it assumes there can be named parameters (even
though we could see that that is not the case).

So fixing the codegen in this case would not solve this problem​:

$ 6 'm​:2nd/./; dd $/'
No such method 'match' for invocant of type ‘Any'

The only way I see we could fix this, is by adding an Any.match or
a
Mu.match, that would just set $/ to Nil.

I'm 10 months late to the party, but this looks off to me.

The commit adds a `.match` method that does nothing to virtually every
object.
The listed reasoning is that `m/./` codegens differently than `/./`
but
that's still the case​: `/./` constructs a Regex object (and in non-
Bool context
no match against $_ is done), while `m/./` performs a match with $_,
so it
wasn't surprising that `m/./` would complain about "no .match on Any",
while `/./` didn't.

Seems the new behaviour simply hides a bug in user's code, so I'm
hesitant
to add it as a requirement to the language spec.

In addition, I see this difference in the actual "match against $_" thing​:

  <Zoffix__> m​: $_ = 'not right'; sub { $_ = Str; say so /./ }()
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «True␤»
  <Zoffix__> m​: $_ = 'not right'; sub { $_ = Str; say so m/./ }()
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «Use of uninitialized value of type Str in string context.␤Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.␤False␤ in sub at <tmp> line 1␤»

Regex.Bool looks[^1] up the callstack for the first .DEFINITE `$_`, whereas, the `m/./` form just uses whatever lexical $_ is available.
Were both behaving the same, the OP's code would produce the same behaviour. IMO what `m/./` does is more correct, as a buggy
piece of code that sets $_ to a typeobject all of a sudden makes `/./` match some data the user likely never meant to match against.

[1] https://github.com/rakudo/rakudo/blob/ebb0521bd/src/core/Regex.pm#L83
[2] https://github.com/rakudo/rakudo/blob/ebb0521bd/src/Perl6/Actions.nqp#L7962-L7967

@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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.