gradient icon indicating copy to clipboard operation
gradient copied to clipboard

Type error in GenServer in TypedServer demo

Open erszcz opened this issue 2 years ago • 2 comments

When any of the TypedGenServer.StageN.Server modules get use GenServer uncommented Gradient.type_check_file reports:

iex(7)> recompile(); Gradient.type_check_file(:code.which( TypedGenServer.Stage1.Server ), [:infer])
Compiling 1 file (.ex)
lib/typed_gen_server/stage1.ex: The variable on line 755 is expected to have type child_spec() | {module(), term()} | module() but it has type %{
  optional(:id) => TypedGenServer.Stage1.Server,
  optional(:start) => {TypedGenServer.Stage1.Server, :start_link, nonempty_list(any())}
}


:error

Not to clutter the demo we just comment GenServer use out, but ultimately, we want GenServer to type check properly - either by fixing it if there's an actual problem, or by fixing a false positive if it is one.

erszcz avatar Mar 21 '22 13:03 erszcz

Upon closer inspection I see that this is the same problem of incorrect map type inference based on a map creation expression. This was reported by @eksperimental in #30 and is tracked upstream in josefs/gradualizer#378. I.e. the bug is in the type checker.

erszcz avatar Apr 27 '22 11:04 erszcz

The inferred type should be:

%{
 :id => TypedGenServer.Stage1.Server,
 :start => {TypedGenServer.Stage1.Server, :start_link, nonempty_list(any())}
}

instead of

%{
  optional(:id) => TypedGenServer.Stage1.Server,
  optional(:start) => {TypedGenServer.Stage1.Server, :start_link, nonempty_list(any())}
}

erszcz avatar Apr 27 '22 11:04 erszcz