xou / elixlsx

An Elixir XLSX writer
MIT License
293 stars 116 forks source link

Dialyzer warning on Workbook.append_sheet() #146

Open ktekinay opened 7 months ago

ktekinay commented 7 months ago

This code, as given in the doc example, works but generates a dialyzer warning about breaking the contract:

Workbook.append_sheet(%Workbook{}, Sheet.with_name("blah"))

This does not:

bogus_sheet = Sheet.with_name("Unused")
Workbook.append_sheet(%Workbook{sheets: [bogus_sheet]}, Sheet.with_name("blah))

But of course that gives us two sheets.

The problem appears to be in the Workbook module, line 16, which defines sheets as nonempty_list. This makes sense once the sheet is created, but not during creation.

The workaround might be to avoid append_sheet for creation and use %Workbook{sheets: [sheet]} instead.

Suggestion: add a Workbook.new(sheet) function.