Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialyzer blames Erlang header instead of LFE code #494

Open
dendrown opened this issue Jul 22, 2024 · 3 comments
Open

Dialyzer blames Erlang header instead of LFE code #494

dendrown opened this issue Jul 22, 2024 · 3 comments

Comments

@dendrown
Copy link

Hello. There seems to be a strange issue when running rebar3 dialyzer on LFE modules that include an Erlang header file. A warning in the LFE code is flagged as occurring in the Erlang header file.

Take, for example, a project with this source file pets.lfe:

(defmodule pets
  (export
   (test 0)))

(include-file "include/dog.lfe")
(include-lib "include/cat.hrl")

(defun test () 
  "Show the problem."
  (flet (;; CALLED IN MAIN BODY
         (doggie () 
           (io:format "DOG: ~p~n" `(,(make-dog))))

         ;; NEVER CALLED!
         (kitty () 
           (io:format "CAT: ~p~n" `(,(make-cat)))))
    (doggie)))

The dog record is defined in include/dog.lfe:

(defrecord dog
  (name 'fido))

The cat record in include/cat.hrl:

-record(cat,
        {name = pickles}).

Running dialyzer detects that we never call (kitty) from the flet, but dialyzer reports the issue in cat.hrl.

$ rebar3 dialyzer
===> Verifying dependencies...
.
.
.
===> Analyzing 1 files with _build/default/rebar3_26.2.1_plt...

src/include/cat.hrl
Line 8: Function '-lfe-test/0-local-kitty/0-1-'/0 will never be called
===> Warnings written to _build/default/26.2.1.dialyzer_warnings
===> Warnings occurred running dialyzer: 1

I put this example together for this issue, but we have seen the problem a number of times in our larger project. I hope it isn't too obscure, and I appreciate your looking
into it when you get a chance.

@dendrown
Copy link
Author

For reference we found the problem on these versions:
lfe: 2.1.2
erlang: 26.2.1
rebar: 3.22.1
rebar_lfe: 0.4.9

We upgraded to rebar 3.23.0 and rebar_lfe 0.4.10 to see if that affected anything. It did not.

We looked into upgrading to lfe 2.1.4, but it breaks our build.

@rvirding
Copy link
Member

Why/how does going to lfe 2.1.4 break your build? There is very little that happened between 2.1.3 and 2.14: a small change in the Makefile c97a44f

@dendrown
Copy link
Author

dendrown commented Jul 31, 2024

So, we were bringing in 2.1.2 via the shortcut in deps in our rebar.config:

diff --git a/rebar.config b/rebar.config
index 77ae003..ef18eb8 100644
--- a/rebar.config
+++ b/rebar.config
@@ -4,7 +4,7 @@
 
 {deps, [
     % NOTE: lfe 2.1.4 is available but may cause build issues (Uncaught error in rebar_core)
-    {lfe,           "2.1.2"},
+    {lfe,           "2.1.4"},
     {lager,         "3.9.2"},
     {jsx,           "3.1.0"},
     {uuid,          "2.0.6", {pkg, uuid_erl}},

But with 2.1.4, it causes an error when we upgrade:

❯ rebar3 unlock --all
❯ rebar3 upgrade --all
===> Verifying dependencies...
===> Package not found in any repo: lfe 2.1.4

So, we do it the long way:

diff --git a/rebar.config b/rebar.config
index 77ae003..08d2374 100644
--- a/rebar.config
+++ b/rebar.config
@@ -4,7 +4,7 @@
 
 {deps, [
     % NOTE: lfe 2.1.4 is available but may cause build issues (Uncaught error in rebar_core)
-    {lfe,           "2.1.2"},
+    {lfe,           {git, "https://github.com/lfe/lfe", {tag, "2.1.4"}}},

We can then unlock & upgrade successfully, but when we try to build our project:

❯ rebar3 compile
===> Verifying dependencies...
===> Uncaught error in rebar_core. Run with DIAGNOSTIC=1 to see stacktrace or consult rebar3.crashdump
===> When submitting a bug report, please include the output of `rebar3 report "your command"`

❯ rebar3 lfe compile
===> Verifying dependencies...
===> Uncaught error in rebar_core. Run with DIAGNOSTIC=1 to see stacktrace or consult rebar3.crashdump
===> When submitting a bug report, please include the output of `rebar3 report "your command"

The resulting rebar3.crashdump looks like this:

Error: {case_clause,
           {error,
               {function_clause,
                   [{lfe_types,to_func_spec,
                        [[[[],[binary]]],11],
                        [{file,
                             "/home/dend/defun/llbeam/_build/default/lib/lfe/src/lfe_types.erl"},
                         {line,340}]},
                    {lists,map,2,[{file,"lists.erl"},{line,1559}]},
                    {lfe_codegen,comp_function_spec,3,
                        [{file,
                             "/home/dend/defun/llbeam/_build/default/lib/lfe/src/lfe_codegen.erl"},
                         {line,406}]},
                    {lists,flatmap_1,2,[{file,"lists.erl"},{line,1579}]},
                    {lists,flatmap_1,2,[{file,"lists.erl"},{line,1579}]},
                    {lfe_codegen,compile_attributes,1,
                        [{file,
                             "/home/dend/defun/llbeam/_build/default/lib/lfe/src/lfe_codegen.erl"},
                         {line,318}]},
                    {lfe_codegen,compile_module,2,
                        [{file,
                             "/home/dend/defun/llbeam/_build/default/lib/lfe/src/lfe_codegen.erl"},
                         {line,90}]},
                    {lfe_codegen,module,2,
                        [{file,
                             "/home/dend/defun/llbeam/_build/default/lib/lfe/src/lfe_codegen.erl"},
                         {line,75}]}]}}}
[{rebar3_lfe_prv_compile,compile_file,3,
                         [{file,"/home/dend/defun/llbeam/_build/default/plugins/rebar3_lfe/src/rebar3_lfe_prv_compile.erl"},
                          {line,103}]},
 {rebar_base_compiler,compile_each,3,
                      [{file,"/home/runner/work/rebar3/rebar3/apps/rebar/src/rebar_base_compiler.erl"},
                       {line,211}]},
 {rebar3_lfe_prv_compile,'-compile_app/2-lc$^0/1-0-',4,
                         [{file,"/home/dend/defun/llbeam/_build/default/plugins/rebar3_lfe/src/rebar3_lfe_prv_compile.erl"},
                          {line,84}]},
 {rebar3_lfe_prv_compile,compile_app,2,
                         [{file,"/home/dend/defun/llbeam/_build/default/plugins/rebar3_lfe/src/rebar3_lfe_prv_compile.erl"},
                          {line,84}]},
 {rebar3_lfe_prv_compile,'-compile/1-lc$^0/1-0-',2,
                         [{file,"/home/dend/defun/llbeam/_build/default/plugins/rebar3_lfe/src/rebar3_lfe_prv_compile.erl"},
                          {line,54}]},
 {rebar3_lfe_prv_compile,compile,1,
                         [{file,"/home/dend/defun/llbeam/_build/default/plugins/rebar3_lfe/src/rebar3_lfe_prv_compile.erl"},
                          {line,54}]},
 {rebar_core,do,2,
             [{file,"/home/runner/work/rebar3/rebar3/apps/rebar/src/rebar_core.erl"},
              {line,155}]},
 {rebar_prv_do,do_task,5,
               [{file,"/home/runner/work/rebar3/rebar3/apps/rebar/src/rebar_prv_do.erl"},
                {line,87}]}]

And here is the info from rebar3 report:

❯ rebar3 report
Rebar3 report
 version 3.23.0
 generated at 2024-07-31T21:37:41+00:00
=================
Please submit this along with your issue at https://github.com/erlang/rebar3/issues (and feel free to edit out private information, if any)
-----------------
Task: 
Entered as:
  
-----------------
Operating System: x86_64-pc-linux-gnu
ERTS: Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit:ns]
Root Directory: /usr/lib64/erlang
Library directory: /usr/lib64/erlang/lib
-----------------
Loaded Applications:
bbmustache: 1.12.2
certifi: 2.11.0
cf: 0.3.1
common_test: 1.26
compiler: 8.4.1
crypto: 5.4
cth_readable: 1.5.1
dialyzer: 5.1.2
edoc: 1.2.1
erlware_commons: 1.7.0
eunit: 2.9
eunit_formatters: 0.5.0
getopt: 1.0.2
inets: 9.1
kernel: 9.2
providers: 1.9.0
public_key: 1.15
relx: 4.9.0
sasl: 4.2.1
snmp: 5.15
ssl_verify_fun: 1.1.6
stdlib: 5.2
syntax_tools: 3.1
tools: 3.6

-----------------
Escript path: undefined
Providers:
  alias app_discovery as check clean clean clean-all clean-build clean-cache cmd compile compile compile completion confabulate cover ct cut deps dialyzer do docs edoc escriptize escriptize eunit get-deps help install install_deps key lint list lock ltest manifest new owner path pkgs publish release release relup repl repo report repos retire revert run run-escript run-release search shell state tar tree unlock update upgrade upgrade upgrade user vendor version versions xref 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants