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

- ruby27.y: accept const names as hash keys for pattern matching #717

Merged
merged 1 commit into from Jun 30, 2020

Conversation

@koic
Copy link
Collaborator

@koic koic commented Jun 30, 2020

Resolves: rubocop-hq/rubocop#8165

This PR fixes the following error for pattern matching.

% ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17]

% ruby-parse -e 'pattern in { Foo: foo }'
(fragment:0):1:14: error: formal argument cannot be a constant
(fragment:0):1: pattern in { Foo: foo }
(fragment:0):1:              ^~~~

Because of that, this PR removes the check for kwarg name to a hash object, and accepts the same case as Ruby:

% ruby -ce 'pattern in { Foo: foo }'
-e:1: warning: Pattern matching is experimental, and the behavior may
change in future versions of Ruby!
Syntax OK

It makes the same changes for ruby28.y (experimental).

Resolves: rubocop-hq/rubocop#8165

This PR fixes the following error for pattern matching.

```console
% ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17]

% ruby-parse -e 'pattern in { Foo: foo }'
(fragment:0):1:14: error: formal argument cannot be a constant
(fragment:0):1: pattern in { Foo: foo }
(fragment:0):1:              ^~~~
```

Because of that, this PR removes the check for kwarg name to a hash object,
and accepts the same case as Ruby:

```console
% ruby -ce 'pattern in { Foo: foo }'
-e:1: warning: Pattern matching is experimental, and the behavior may
change in future versions of Ruby!
Syntax OK
```

It makes the same changes for ruby28.y (experimental).
@iliabylich iliabylich changed the title - ruby27.y: Fix an error for pattern matching - ruby27.y: accept const names as hash keys for pattern matching Jun 30, 2020
@iliabylich iliabylich merged commit db3d450 into whitequark:master Jun 30, 2020
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@iliabylich
Copy link
Collaborator

@iliabylich iliabylich commented Jun 30, 2020

@koic Thanks!

@koic koic deleted the koic:fix_error_for_pattern_matching branch Jul 1, 2020
koic added a commit to koic/rubocop that referenced this pull request Sep 24, 2020
@koic koic mentioned this pull request Sep 24, 2020
8 of 8 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.