I created a project using the command:
mix phx.new elixir_api \
--no-assets \
--no-dashboard \
--no-ecto \
--no-gettext \
--no-html \
--no-mailer \
--binary-id
Then I opened the project in VSCode and browsed to the file ./lib/elixir_api_web/router.ex
and the IDE shows me a warning like this:
The pattern can never match the type.
Pattern:
{_, _, _, _}
Type:
:error
ElixirLS Dialyzer
The file has only the automatically generated code. Why is this warning appearing then, since when running the application it doesn’t bring me any warning messages?
1 Like
That message appears to be related to --no-html
, based on the last comment here:
opened 02:56PM - 22 Mar 23 UTC
closed 02:58PM - 22 Mar 23 UTC
### Environment
* Elixir version (elixir -v): 1.14.3
* Phoenix version (mix … deps): 1.7.2
* Operating system: MacOS Ventura 13.2.1
### Expected behavior
```bash
> mix phx.new phx_test --no-html
> cd phx_test
> code .
```
After ElixirLS has done its thing, no warnings should be visible in the problems tab
### Actual behavior
Without editing anything, the Dialyzer reports two warnings in `lib/phx_test_web/router.ex`:
```elixir
use PhxTestWeb, :router Function call/2 has no local return
```
At end of file
```elixir
end
The pattern
{_@10, _@11, _@12, _@13} can never match the type
'error'
```
### Analysis
I have tried almost all permutations of `--no-xx` and only `--no-html` will generate these warnings whenever used. For the life of me I cannot find what differs in the generated code. I have even tried adding the only missing line in `def router` - `import Phoenix.LiveView.Router` (and required dependencies), but it does nothing. Removing everything but `def router` does not help either.
3 Likes
TL;DR: You can’t have an empty scope
statement (no routes) in router.ex