# About method overloading（Error: missing argument）

**URL:** <https://forum.crystal-lang.org/t/about-method-overloading-error-missing-argument/4007>\
**Category:** Help & Support\
**Created:** [October 26, 2021, 3:45am UTC](https://forum.crystal-lang.org/t/about-method-overloading-error-missing-argument/4007 "2021-10-26T03:45:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![orangeSi](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/orangesi/32/1569_2.png) [@orangeSi](https://forum.crystal-lang.org/u/orangeSi)\
**Post date:** [October 26, 2021, 3:45am UTC](https://forum.crystal-lang.org/t/about-method-overloading-error-missing-argument/4007/1 "2021-10-26T03:45:53Z")

</div>

Hello, everyone! I got below error when use overloading:

```auto
$ cat demo.cr 
class A
    def self.x(b : String)
      puts("x1=#{b}")
    end
    def self.x(c : String)
      puts("x2=#{c}")
    end
end
A.x(b: "b")
A.x(c: "c")

$ crystal build demo.cr 
Showing last frame. Use --error-trace for full trace.

In demo.cr:10:3

 10 | A.x(b: "b")
        ^
Error: missing argument: c

Overloads are:
 - A.x(c : String)

```

And my expection output is:

```auto
x1=b
x2=c

```

I had seen [Overloading - Crystal](https://crystal-lang.org/reference/syntax_and_semantics/overloading.html), and search in forum by keyword overload, but still not understand the above error ~

Thanks~  
Si

---

<div class="post-metadata">

**Author:** ![jgaskins](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jgaskins/32/2449_2.png) [@jgaskins](https://forum.crystal-lang.org/u/jgaskins)\
**Post date:** [October 26, 2021, 5:02am UTC](https://forum.crystal-lang.org/t/about-method-overloading-error-missing-argument/4007/2 "2021-10-26T05:02:58Z")

</div>

By default, Crystal looks at method signatures purely as positional arguments, so if you write two methods that take a `String`, the second doesn’t _overload_ the first, it _overwrites_ it. This confused me, too, but it makes sense from a certain perspective — if you pass positional arguments to the method, which one gets called?

If you want to be able to distinguish method signatures using keyword arguments, you have to force them to be keyword arguments. You can separate positional arguments from keyword arguments in a method signature with a `*` in the arg list. If you don’t want positional arguments at all (as is the case here), you can use `*` in the first argument spot:

```crystal
class A
  def self.x(*, b : String)
    puts("x1=#{b}")
  end

  def self.x(*, c : String)
    puts("x2=#{c}")
  end
end

```

---

<div class="post-metadata">

**Author:** ![orangeSi](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/orangesi/32/1569_2.png) [@orangeSi](https://forum.crystal-lang.org/u/orangeSi)\
**Post date:** [October 26, 2021, 5:36am UTC](https://forum.crystal-lang.org/t/about-method-overloading-error-missing-argument/4007/3 "2021-10-26T05:36:42Z")

</div>

It works! Thanks~
