(Solved) Surface live component slot arg create weird dialyzer pattern_match error

While changing some live component to surface live component,
Dialyzer gave an error like below:

lib/~some_path~/index.sface:1:pattern_match
The pattern can never match the type.

Pattern:
false

Type:
true

As it shows no useful line number, and there was no error when compiling and running the code, I had to find it by commenting out binary search the source code.

Below is part of the index code where it used live component before changing to surface:

<live_component module={SomeModule} id="some-id" data={@some_data} :let={prop}>
  <button phx-click={prop.on_click} >button</button>
</.live_component>

After changing to surface live component:

<SomeModule id="some-id" data={@some_data} :let={prop}>
  <button phx-click={prop.on_click} >button</button>
</SomeModule>

The problem was getting slot argument as whole prop variable.
I don’t know why it broke Dialyzer, and there was no error from Surface.
But after changing to the following, Dialyzer error disappeared:

<SomeModule id="some-id" data={@some_data} :let={on_click: on_click}>
  <button phx-click={on_click} >button</button>
</SomeModule>

I couldn’t make a reproducible example,
so I’m leaving this note just in case anyone stumbles upon a similar problem.

1 Like