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

Elvis complains about dynamic function call in behaviour module #467

Closed
kzemek opened this issue Jul 26, 2017 · 4 comments
Closed

Elvis complains about dynamic function call in behaviour module #467

kzemek opened this issue Jul 26, 2017 · 4 comments

Comments

@kzemek
Copy link

kzemek commented Jul 26, 2017

The callback is defined in the module, but Elvis complains about dynamic function call on a line in the same module.

@elbrujohalcon
Copy link
Member

I could isolate the issue.

This code generates no warnings:

-module(x).
%-include("x.hrl").
-callback x() -> _.
x(X) -> X:x().

This code generates warnings:

-module(x).
-include("x.hrl").
-callback x() -> _.
x(X) -> X:x().

This code generates no warnings either:

-module(x).
-author("x.hrl").
-callback x() -> _.
x(X) -> X:x().

@elbrujohalcon
Copy link
Member

Digging deeper, it looks like aleppo is misunderstanding include attributes.

1> MinContent = "-module(x).\n-include(\"x.hrl\").",
{ok, MinTokens, _} = erl_scan:string(MinContent, {1,1}, [text]),
rp({MinTokens, aleppo:process_tokens(MinTokens)}).
{[{'-',[{text,"-"},{location,{1,1}}]},
  {atom,[{text,"module"},{location,{1,2}}],module},
  {'(',[{text,"("},{location,{1,8}}]},
  {atom,[{text,"x"},{location,{1,9}}],x},
  {')',[{text,")"},{location,{1,10}}]},
  {dot,[{text,".\n"},{location,{1,11}}]},
  {'-',[{text,"-"},{location,{2,1}}]},
  {atom,[{text,"include"},{location,{2,2}}],include},
  {'(',[{text,"("},{location,{2,9}}]},
  {string,[{text,"\"x.hrl\""},{location,{2,10}}],"x.hrl"},
  {')',[{text,")"},{location,{2,17}}]},
  {dot,[{text,"."},{location,{2,18}}]}],
 {ok,[{'-',[{location,{1,1}},{text,"-"},{location,{1,1}}]},
      {atom,[{location,{1,2}},{text,"module"},{location,{1,2}}],
            module},
      {'(',[{location,{1,8}},{text,"("},{location,{1,8}}]},
      {atom,[{location,{1,9}},{text,"x"},{location,{1,9}}],x},
      {')',[{location,{1,10}},{text,")"},{location,{1,10}}]},
      {dot,[{location,{1,11}},{text,".\n"},{location,{1,11}}]},
      {string,[{location,{2,10}},
               {text,"\"x.hrl\""},
               {location,{2,10}}],
              "x.hrl"},
      {eof,0}]}}
ok

As you can see… aleppo is interpreting -include("x.hrl"). as just…

      {string,[{location,{2,10}},
               {text,"\"x.hrl\""},
               {location,{2,10}}],
              "x.hrl"},

…as if it was just "x.hrl", i.e. the string floating around in the module.

@elbrujohalcon
Copy link
Member

This is related to #468 since, as stated in inaka/aleppo#45, it can be fixed by providing a proper list of include folders to ktn_code:parse_tree.

@harenson
Copy link
Member

harenson commented Aug 1, 2017

@kzemek in the meantime you could use elvis_core@0.3.9 and set proper include_dirs value so elvis can send it to aleppo.

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

3 participants