# "no overload matches" compile error on seemly matching constructor signatures

**URL:** <https://forum.crystal-lang.org/t/no-overload-matches-compile-error-on-seemly-matching-constructor-signatures/5478>\
**Category:** Help & Support\
**Created:** [March 12, 2023, 5:50pm UTC](https://forum.crystal-lang.org/t/no-overload-matches-compile-error-on-seemly-matching-constructor-signatures/5478 "2023-03-12T17:50:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eric](https://forum.crystal-lang.org/u/eric)\
**Post date:** [March 12, 2023, 5:50pm UTC](https://forum.crystal-lang.org/t/no-overload-matches-compile-error-on-seemly-matching-constructor-signatures/5478/1 "2023-03-12T17:50:17Z")

</div>

I have the following definitions (clipping out parts not relevant):

```crystal
abstract class Change
  ...
  def initialize(@model : ModelInterface, @unit : Unit)
  end
  ...
  abstract class NoOption < Change
    ...
  end
  ...
end

class Change::Outline < Change::NoOption
  ...
end

module ModelInterface
  ...
end

class LanguageModel
  include ModelInterface
  ...
end

abstract class Unit
  ...
end

```

I have some code that looks like:

```auto
@change_class.as(Change::NoOption).new @model, @unit

```

When I attempt to compile I get the following error:

```sh
 78 | @change_class.as(Change::NoOption).new @model, @unit
                                         ^--
Error: no overload matches 'Change::Outline#new' with types LanguageModel, Unit+

Overloads are:
 - Change.new(model : ModelInterface, unit : Unit)

```

I’m not clear on what the mismatch is. My constructor is defined as taking a `ModelInterface` and some subclass of `Unit`. The error indicates I am sending it a `LanguageModel` (which `ModelInterface` is mixed into) and some subclass of `Unit`. What I am I missing? Those seem to match.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [March 12, 2023, 6:24pm UTC](https://forum.crystal-lang.org/t/no-overload-matches-compile-error-on-seemly-matching-constructor-signatures/5478/2 "2023-03-12T18:24:31Z")

</div>

`@change_class.as(Change::NoOption)` casts `@change_class` to an _instance_ of `Change::NoOption`, so your code is trying to call an _instance method_ (`#new`). The constructor would be a _class method_ (`.new`).

You might want to cast to the metaclass of `Change::Option` as `@change_class.as(Change::NoOption.class)`.

---

<div class="post-metadata">

**Author:** ![eric](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eric](https://forum.crystal-lang.org/u/eric)\
**Post date:** [March 12, 2023, 6:45pm UTC](https://forum.crystal-lang.org/t/no-overload-matches-compile-error-on-seemly-matching-constructor-signatures/5478/3 "2023-03-12T18:45:51Z")

</div>

🤦‍♂️ - I might have eventually seen that but you saved me a lot of time. I was so focused on if the args were matching I missed that was restricting the type incorrectly. I even had similar code elsewhere that was doing it right but somehow missed it here. Thanks!
