Skip to content

Commit 5481bcb

Browse files
authored
Fix crash in edts_code:get_compile_cwd/2 (#288)
If a module has expanded records, the first attribute in the abstract code is not about the module itself but rather a compiler option that has been implicitly added by the Erlang compiler. For example: ``` [{abstract_code, {raw_abstract_v1, [{attribute,0,compile,{nowarn_unused_record,[[three]]}}, {attribute,{1,1},file,{"src/three.erl",1}}, ``` --------- Authored-by: Phu Lien <plienton@cisco.com>
1 parent d38f538 commit 5481bcb

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

lib/edts/src/edts_code.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ get_compile_cwd(M, [{attribute,_,file,{RelPath,1}}|_]) ->
356356
case proplists:get_value(cwd, CompileOpts, undefined) of
357357
undefined -> pop_dirs(proplists:get_value(source, CompileInfo), RelPath);
358358
Cwd -> Cwd
359-
end.
359+
end;
360+
get_compile_cwd(M, [{attribute,0,compile,_}|Rest]) ->
361+
get_compile_cwd(M, Rest).
360362

361363
pop_dirs(Source0, Rel) ->
362364
L = length(filename:split(Rel)),

test_data/edts-test-project-project-1/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ERL_LIBS = $(shell pwd)/lib
33
all:
44
@cd lib/one; erlc -o ebin +debug_info src/*.erl
55
@cd lib/two; erlc -o ebin +debug_info src/*.erl
6+
@cd lib/three; erlc -o ebin +debug_info src/*.erl
67

78
clean:
89
@rm -f lib/*/ebin/*.beam

test_data/edts-test-project-project-1/lib/three/ebin/.gitignore

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-record(three, {type :: atom()}).
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-module(three).
2+
3+
-include("../include/three.hrl").
4+
-include_lib("stdlib/include/ms_transform.hrl").
5+
6+
-export([three_fun/1]).
7+
8+
three_fun(Expected) ->
9+
MS = ets:fun2ms(fun(#three{type = Type}) when Type == Expected -> true end),
10+
ets:select(?MODULE, MS).
11+
12+
%%%_* Emacs ====================================================================
13+
%%% Local Variables:
14+
%%% erlang-indent-level: 2
15+
%%% End:

0 commit comments

Comments
 (0)