ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:109813] [Ruby master Bug#18990] Pattern matching unexpectedly raises "duplicated key name" error
@ 2022-09-01 15:06 zeke (Zeke Gabrielse)
  2022-09-01 20:00 ` [ruby-core:109818] " henryanvyl (Henry Tseng)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zeke (Zeke Gabrielse) @ 2022-09-01 15:06 UTC (permalink / raw)
  To: ruby-core

Issue #18990 has been reported by zeke (Zeke Gabrielse).

----------------------------------------
Bug #18990: Pattern matching unexpectedly raises "duplicated key name" error
https://bugs.ruby-lang.org/issues/18990

* Author: zeke (Zeke Gabrielse)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin19]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I've found that sometimes, when matching nested patterns, I get an unexpected "duplicate key name" error but there's no duplicate key in any individual pattern. The "duplicated" key is actually in another pattern that's in scope, which I found was odd. (And the fix is even more odd.)

This seems like unexpected behavior to me. There's an example of this behavior below. The patterns in #all? cause the error, even though they're separate lines.

```ruby
class User
  attr_reader :first_name,
              :last_name

  def initialize(first_name:, last_name:)
    @first_name, @last_name = first_name, last_name
  end

  def deconstruct_keys(keys)
    { first_name:, last_name: }
  end
end

users = [
  User.new(first_name: 'Jane', last_name: 'Doe'),
  User.new(first_name: 'Jane', last_name: 'Smith'),
]

# Fails
case users
in [{ first_name: 'John', ** }, *]
  users.all? { _1 in first_name: 'John' }
in [{ first_name: 'Jane', ** }, *]
  users.all? { _1 in first_name: 'Jane' } # => bug.rb:17: duplicated key name
end
```

Counterintuitively, wrapping the pattern in {} resolves the error.

```ruby
# Works
case users
in [{ first_name: 'John', ** }, *]
  users.all? { _1 in { first_name: 'John' } }
in [{ first_name: 'Jane', ** }, *]
  users.all? { _1 in { first_name: 'Jane' } }
end
```

Seems like a bug?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:109818] [Ruby master Bug#18990] Pattern matching unexpectedly raises "duplicated key name" error
  2022-09-01 15:06 [ruby-core:109813] [Ruby master Bug#18990] Pattern matching unexpectedly raises "duplicated key name" error zeke (Zeke Gabrielse)
@ 2022-09-01 20:00 ` henryanvyl (Henry Tseng)
  2022-09-09  5:16 ` [ruby-core:109860] " ktsj (Kazuki Tsujimoto)
  2022-09-10  7:12 ` [ruby-core:109868] " nagachika (Tomoyuki Chikanaga)
  2 siblings, 0 replies; 4+ messages in thread
From: henryanvyl (Henry Tseng) @ 2022-09-01 20:00 UTC (permalink / raw)
  To: ruby-core

Issue #18990 has been updated by henryanvyl (Henry Tseng).


Verifying that this occurs in ruby 3.1.0 but does not exist in 3.2.x

----------------------------------------
Bug #18990: Pattern matching unexpectedly raises "duplicated key name" error
https://bugs.ruby-lang.org/issues/18990#change-99057

* Author: zeke (Zeke Gabrielse)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin19]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I've found that sometimes, when matching nested patterns, I get an unexpected "duplicate key name" error but there's no duplicate key in any individual pattern. The "duplicated" key is actually in another pattern that's in scope, which I found was odd. (And the fix is even more odd.)

This seems like unexpected behavior to me. There's an example of this behavior below. The patterns in #all? cause the error, even though they're separate lines.

```ruby
class User
  attr_reader :first_name,
              :last_name

  def initialize(first_name:, last_name:)
    @first_name, @last_name = first_name, last_name
  end

  def deconstruct_keys(keys)
    { first_name:, last_name: }
  end
end

users = [
  User.new(first_name: 'Jane', last_name: 'Doe'),
  User.new(first_name: 'Jane', last_name: 'Smith'),
]

# Fails
case users
in [{ first_name: 'John', ** }, *]
  users.all? { _1 in first_name: 'John' }
in [{ first_name: 'Jane', ** }, *]
  users.all? { _1 in first_name: 'Jane' } # => bug.rb:17: duplicated key name
end
```

Counterintuitively, wrapping the pattern in {} resolves the error.

```ruby
# Works
case users
in [{ first_name: 'John', ** }, *]
  users.all? { _1 in { first_name: 'John' } }
in [{ first_name: 'Jane', ** }, *]
  users.all? { _1 in { first_name: 'Jane' } }
end
```

Seems like a bug?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:109860] [Ruby master Bug#18990] Pattern matching unexpectedly raises "duplicated key name" error
  2022-09-01 15:06 [ruby-core:109813] [Ruby master Bug#18990] Pattern matching unexpectedly raises "duplicated key name" error zeke (Zeke Gabrielse)
  2022-09-01 20:00 ` [ruby-core:109818] " henryanvyl (Henry Tseng)
@ 2022-09-09  5:16 ` ktsj (Kazuki Tsujimoto)
  2022-09-10  7:12 ` [ruby-core:109868] " nagachika (Tomoyuki Chikanaga)
  2 siblings, 0 replies; 4+ messages in thread
From: ktsj (Kazuki Tsujimoto) @ 2022-09-09  5:16 UTC (permalink / raw)
  To: ruby-core

Issue #18990 has been updated by ktsj (Kazuki Tsujimoto).

Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN to 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: REQUIRED

@zeke 
Thanks for reporting.

----------------------------------------
Bug #18990: Pattern matching unexpectedly raises "duplicated key name" error
https://bugs.ruby-lang.org/issues/18990#change-99099

* Author: zeke (Zeke Gabrielse)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin19]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: REQUIRED
----------------------------------------
I've found that sometimes, when matching nested patterns, I get an unexpected "duplicate key name" error but there's no duplicate key in any individual pattern. The "duplicated" key is actually in another pattern that's in scope, which I found was odd. (And the fix is even more odd.)

This seems like unexpected behavior to me. There's an example of this behavior below. The patterns in #all? cause the error, even though they're separate lines.

```ruby
class User
  attr_reader :first_name,
              :last_name

  def initialize(first_name:, last_name:)
    @first_name, @last_name = first_name, last_name
  end

  def deconstruct_keys(keys)
    { first_name:, last_name: }
  end
end

users = [
  User.new(first_name: 'Jane', last_name: 'Doe'),
  User.new(first_name: 'Jane', last_name: 'Smith'),
]

# Fails
case users
in [{ first_name: 'John', ** }, *]
  users.all? { _1 in first_name: 'John' }
in [{ first_name: 'Jane', ** }, *]
  users.all? { _1 in first_name: 'Jane' } # => bug.rb:17: duplicated key name
end
```

Counterintuitively, wrapping the pattern in {} resolves the error.

```ruby
# Works
case users
in [{ first_name: 'John', ** }, *]
  users.all? { _1 in { first_name: 'John' } }
in [{ first_name: 'Jane', ** }, *]
  users.all? { _1 in { first_name: 'Jane' } }
end
```

Seems like a bug?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:109868] [Ruby master Bug#18990] Pattern matching unexpectedly raises "duplicated key name" error
  2022-09-01 15:06 [ruby-core:109813] [Ruby master Bug#18990] Pattern matching unexpectedly raises "duplicated key name" error zeke (Zeke Gabrielse)
  2022-09-01 20:00 ` [ruby-core:109818] " henryanvyl (Henry Tseng)
  2022-09-09  5:16 ` [ruby-core:109860] " ktsj (Kazuki Tsujimoto)
@ 2022-09-10  7:12 ` nagachika (Tomoyuki Chikanaga)
  2 siblings, 0 replies; 4+ messages in thread
From: nagachika (Tomoyuki Chikanaga) @ 2022-09-10  7:12 UTC (permalink / raw)
  To: ruby-core

Issue #18990 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.7: DONTNEED, 3.0: DONTNEED, 3.1: REQUIRED to 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONE

ruby_3_1 163947f4dc031bb5e619ae64ad4a6a02f8885717 merged revision(s) db0e0dad1171456253ebd899e7e878823923d3d8.

----------------------------------------
Bug #18990: Pattern matching unexpectedly raises "duplicated key name" error
https://bugs.ruby-lang.org/issues/18990#change-99108

* Author: zeke (Zeke Gabrielse)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin19]
* Backport: 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONE
----------------------------------------
I've found that sometimes, when matching nested patterns, I get an unexpected "duplicate key name" error but there's no duplicate key in any individual pattern. The "duplicated" key is actually in another pattern that's in scope, which I found was odd. (And the fix is even more odd.)

This seems like unexpected behavior to me. There's an example of this behavior below. The patterns in #all? cause the error, even though they're separate lines.

```ruby
class User
  attr_reader :first_name,
              :last_name

  def initialize(first_name:, last_name:)
    @first_name, @last_name = first_name, last_name
  end

  def deconstruct_keys(keys)
    { first_name:, last_name: }
  end
end

users = [
  User.new(first_name: 'Jane', last_name: 'Doe'),
  User.new(first_name: 'Jane', last_name: 'Smith'),
]

# Fails
case users
in [{ first_name: 'John', ** }, *]
  users.all? { _1 in first_name: 'John' }
in [{ first_name: 'Jane', ** }, *]
  users.all? { _1 in first_name: 'Jane' } # => bug.rb:17: duplicated key name
end
```

Counterintuitively, wrapping the pattern in {} resolves the error.

```ruby
# Works
case users
in [{ first_name: 'John', ** }, *]
  users.all? { _1 in { first_name: 'John' } }
in [{ first_name: 'Jane', ** }, *]
  users.all? { _1 in { first_name: 'Jane' } }
end
```

Seems like a bug?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-10  7:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 15:06 [ruby-core:109813] [Ruby master Bug#18990] Pattern matching unexpectedly raises "duplicated key name" error zeke (Zeke Gabrielse)
2022-09-01 20:00 ` [ruby-core:109818] " henryanvyl (Henry Tseng)
2022-09-09  5:16 ` [ruby-core:109860] " ktsj (Kazuki Tsujimoto)
2022-09-10  7:12 ` [ruby-core:109868] " nagachika (Tomoyuki Chikanaga)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).