[ruby-dev:51062] [Ruby master Bug#17925] Pattern matching syntax using semicolon one-line

From: koic.ito@...
Date: 2021-05-30 08:41:24 UTC
List: ruby-dev #51062
Issue #17925 has been updated by koic (Koichi ITO).=0D
=0D
=0D
> NOTE 1: I understand that only syntax that doesn't use case and end is ex=
perimental one-line pattern matching syntax.=0D
=0D
A little supplement. The following is also an experimental one-line pattern=
 matching syntax since Ruby 3.0, but the `=3D>` one-line pattern matching s=
yntax is no problem.=0D
=0D
```console=0D
% ruby -e "'' =3D> ''"=0D
-e:1: warning: One-line pattern matching is experimental, and the behavior =
may change in future versions of Ruby!=0D
```=0D
=0D
----------------------------------------=0D
Bug #17925: Pattern matching syntax using semicolon one-line=0D
https://bugs.ruby-lang.org/issues/17925#change-92275=0D
=0D
* Author: koic (Koichi ITO)=0D
* Status: Open=0D
* Priority: Normal=0D
* ruby -v: ruby 3.1.0dev (2021-05-28T16:34:27Z master e56ba6231f) [x86_64-d=
arwin19]=0D
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN=0D
----------------------------------------=0D
## Summary=0D
=0D
There are the following differences between `case ... when` and` case ... i=
n`.  Is this an expected behavior?=0D
=0D
```console=0D
% ruby -v=0D
ruby 3.1.0dev (2021-05-28T16:34:27Z master e56ba6231f) [x86_64-darwin19]=0D
=0D
% ruby -ce 'case expression when 42; end'=0D
Syntax OK=0D
=0D
% ruby -ce 'case expression in 42; end'=0D
-e:1: warning: One-line pattern matching is experimental, and the behavior =
may change in future versions of Ruby!=0D
-e:1: syntax error, unexpected `end', expecting `when'=0D
case expression in 42; end=0D
```=0D
=0D
So, I have two concerns.=0D
=0D
- Since the pattern matching syntax is different from `case ... when`,=E3=
=80=80can't user write semicolon one-line `case ... in` in the same semicol=
on one-line as `case ... when`?=0D
- Does `case expression in 42; end` display an experimental warning of one-=
line pattern matching. Right?=0D
=0D
This is reproduced in Ruby 3.1.0-dev and Ruby 3.0.1.=0D
=0D
## Additional Information=0D
=0D
NOTE 1: I understand that only syntax that doesn't use `case` and `end` is =
experimental one-line pattern matching syntax.=0D
=0D
```=0D
% ruby -ce 'expression in 42'=0D
-e:1: warning: One-line pattern matching is experimental, and the behavior =
may change in future versions of Ruby!=0D
Syntax OK=0D
```=0D
=0D
NOTE 2: The syntax is OK if a semicolon is used between `expression` and `i=
n`. But `case ... when` is a valid syntax to omit.=0D
=0D
```=0D
% ruby -e ruby -ce 'case expression; in 42; end'=0D
Syntax OK=0D
```=0D
=0D
=0D
=0D
--=20=0D
https://bugs.ruby-lang.org/=0D

In This Thread