# A double splatting not work with named arguments, is it a bug?

**URL:** <https://forum.crystal-lang.org/t/a-double-splatting-not-work-with-named-arguments-is-it-a-bug/5418>\
**Category:** Help & Support\
**Created:** [February 23, 2023, 4:02pm UTC](https://forum.crystal-lang.org/t/a-double-splatting-not-work-with-named-arguments-is-it-a-bug/5418 "2023-02-23T16:02:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [February 23, 2023, 4:02pm UTC](https://forum.crystal-lang.org/t/a-double-splatting-not-work-with-named-arguments-is-it-a-bug/5418/1 "2023-02-23T16:02:03Z")

</div>

Following code not work.

```auto
	def foo(x, **others)
	  bar(wait: 1, **others) # => syntax error.
	end

	def bar(wait, **others)
	  p others
	end

	foo x: 1, y: 2, z: 3 # => the expected output: {y: 2, z: 3}

```

But following code works

```auto
	def foo(x, **others)
	  bar(1, **others) # => works
	end

	def bar(wait, **others)
	  p others
	end

	foo x: 1, y: 2, z: 3 # => the expected output: {y: 2, z: 3}

```

This leads to a problem, if `foo` want to use double splatting to forward arguments to `bar`,  
the bar can not force use named argument, signature like this never work. `def bar(*, wait, **others)`.

is there any reason for the first code is invalid?

Thanks.

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [February 23, 2023, 4:19pm UTC](https://forum.crystal-lang.org/t/a-double-splatting-not-work-with-named-arguments-is-it-a-bug/5418/2 "2023-02-23T16:19:51Z")

</div>

For simplicity, you need to splat first, then add extra arguments:

```crystal
def foo(x, **others)
  bar(**others, wait: 1) # Note the change here
end

def bar(wait, **others)
  p others
end

foo x: 1, y: 2, z: 3

```

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [February 23, 2023, 4:54pm UTC](https://forum.crystal-lang.org/t/a-double-splatting-not-work-with-named-arguments-is-it-a-bug/5418/3 "2023-02-23T16:54:58Z")

</div>

Thanks, above code works. i can define bar prefix with a `*` like `bar(*, wait, **others)` now.

```auto
def foo(*, x, **others)
  bar(**others, wait: 1)
end

def bar(*, wait, **others)
  p others
end

foo x: 1, y: 2, z: 3 # => the expected output: {y: 2, z: 3}

```

But, i still consider this a little inconsistent, user must invoke bar like `bar(**others, wait: 1)`, but, user can not define method bar like `def bar(*,**others, wait)`.

---

<div class="post-metadata">

**Author:** ![oprypin](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/oprypin/32/859_2.png) [@oprypin](https://forum.crystal-lang.org/u/oprypin)\
**Post date:** [February 24, 2023, 6:16am UTC](https://forum.crystal-lang.org/t/a-double-splatting-not-work-with-named-arguments-is-it-a-bug/5418/4 "2023-02-24T06:16:18Z")

</div>

> <https://github.com/crystal-lang/crystal/issues/2651>
>
> I think this is the logical order of specifying arguments:
> 
> \`\`\` crystal
> def f(a,… b, c, d)
> pp a, b, c, d
> end
> 
> f(1, \*{2}, c: 3, \*\*{d: 4})
> \`\`\`
> 
> However, it is invalid currently, and I am suggesting to allow it.
> 
> This works, though:
> 
> \`\`\` crystal
> f(1, \*{2}, \*\*{d: 4}, c: 3)
> \`\`\`
