WhatsApp / eqwalizer

A type-checker for Erlang
Apache License 2.0
513 stars 29 forks source link

unbound record error #53

Closed tsloughter closed 10 months ago

tsloughter commented 10 months ago

I'm seeing Unbound rec: state in a module but the record definitely exists. It is this module: https://github.com/open-telemetry/opentelemetry-erlang/blob/main/apps/opentelemetry_experimental/src/otel_metric_reader.erl

It gives this error both in the return of init, handle_continue and the first handle_info function.

Unless I misunderstand the eqwalizer error this is clearly a bug when the module compiles succesfully since the record must be defined? And I should just use ignore or I guess fixme to make clear I should be able to remove the workaround in the future?

ilya-klyuchnikov commented 10 months ago

eqWAlizer reports an error about the record state: that it uses a types that is not exported (namely: supervisor:sup_ref()).

elp eqwalize otel_metric_reader
  Loading rebar3 build_info
  Loading applications      ████████████████████ 17/17
  Seeding database
  Compiling dependencies
  eqWAlized                 ████████████████████ 1/1 
error: non_exported_id
   ┌─ apps/opentelemetry_experimental/src/otel_metric_reader.erl:47:26
   │
47 │          provider_sup :: supervisor:sup_ref(),
   │                          ^^^^^^^^^^^^^^^^^^^^ Type exists but is not exported: supervisor:sup_ref/0

error: unbound_record
   ┌─ apps/opentelemetry_experimental/src/otel_metric_reader.erl:89:10
   │
89 │       {ok, #state{exporter=Exporter,
   │ ╭──────────^
90 │ │                 provider_sup=ProviderSup,
91 │ │                 id=ReaderId,
92 │ │                 default_aggregation_mapping=DefaultAggregationMapping,
   · │
95 │ │                 tref=TRef,
96 │ │                 config=Config}, {continue, register_with_server}}.
   │ ╰──────────────────────────────^ Unbound rec: state

Then internally eqWAlizer "cancels" such a record - this is why its reported as an unbound record. It seems that a path forward would be to fix the type of the field provider_sup.

tsloughter commented 10 months ago

@ilya-klyuchnikov aah. I had put a fixme on that supervisor error (there should eventually be such a type exported) so it wasn't showing in the errors and didn't think about it could still cause a record to be "canceled".

Thanks!