josefs / Gradualizer

A Gradual type system for Erlang
MIT License
613 stars 35 forks source link

Log changes to variable types in #env.venv #529

Closed erszcz closed 1 year ago

erszcz commented 1 year ago

This is an attempt at, at least partially, addressing #527.

For the following code:

-module(test).

-spec s(integer()) -> string().
s(S) ->
    Z = 123,
    S + 12.

Instead of this verbose log:

$ ./bin/gradualizer --verbose --infer test.erl
Checking module test
Spawning async task...
Checking function s/1
Pushing {clauses_controls,true}
4:1: Checking clause :: string()
5:9: Propagated type of 123 :: 123
5:5: Propagated type of Z = 123 :: 123
6:7: Checking that S + 12 :: string()
Task returned from function s/1 with [{type_error,arith_error,'+',
                                       {6,7},
                                       {type,0,string,[]}}]
test.erl: The operator '+' on line 6 at column 7 is expected to have type string() which has no numeric subtypes

We'll now get this:

$ ./bin/gradualizer --verbose --infer test.erl
Checking module test
Spawning async task...
Checking function s/1
Pushing {clauses_controls,true}
4:1: Checking clause :: string()
4:3: Setting var type S :: integer()
5:9: Propagated type of 123 :: 123
5:5: Setting var type Z :: 123
5:5: Propagated type of Z = 123 :: 123
6:7: Checking that S + 12 :: string()
Task returned from function s/1 with [{type_error,arith_error,'+',
                                       {6,7},
                                       {type,0,string,[]}}]
test.erl: The operator '+' on line 6 at column 7 is expected to have type string() which has no numeric subtypes