Skip to content

Commit fe01aee

Browse files
alanzmeta-codesync[bot]
authored andcommitted
15/n ifdef: Fix MacroExpCtx to search past includes
Summary: - Fix `find_define` and `find_defines_by_name` in `MacroExpCtx` to continue searching past `#include` directives instead of stopping - Previously, `find_define` returned `None` and `find_defines_by_name` broke out of the loop when encountering an include, causing macros defined before an include to be missed - Add tests verifying that defines are found across include boundaries Reviewed By: TD5 Differential Revision: D94369223 fbshipit-source-id: c48b5d110e606eccf7089d7e60da5ba7efba9b7e
1 parent 46b4ade commit fe01aee

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

crates/hir/src/macro_exp.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ impl<'a> MacroExpCtx<'a> {
312312
return None;
313313
}
314314
PPDirective::Undef { .. } => {}
315-
// TODO: recurse into includes
316-
PPDirective::Include { .. } => return None,
315+
PPDirective::Include { .. } => continue,
317316
}
318317
}
319318

@@ -342,8 +341,7 @@ impl<'a> MacroExpCtx<'a> {
342341
}
343342
}
344343
PPDirective::Undef { .. } => {}
345-
// TODO: recurse into includes
346-
PPDirective::Include { .. } => break,
344+
PPDirective::Include { .. } => continue,
347345
}
348346
}
349347

@@ -721,6 +719,37 @@ bar() -> ?~FOO.
721719
-endif.
722720
-define(FOO(), active2).
723721
bar() -> ?~FOO.
722+
"#,
723+
2,
724+
);
725+
}
726+
727+
#[test]
728+
fn find_define_searches_past_include() {
729+
// A define before an include should be found by find_define
730+
check_user_condition_aware(
731+
r#"
732+
//- /src/main.erl
733+
-define(X, 1).
734+
%% ^^^^^^^^^^^^^^
735+
-include("h.hrl").
736+
f() -> ?~X.
737+
//- /src/h.hrl
738+
"#,
739+
);
740+
}
741+
742+
#[test]
743+
fn find_defines_by_name_searches_past_include() {
744+
// find_defines_by_name should find defines on both sides of an include
745+
check_defines_count_condition_aware(
746+
r#"
747+
//- /src/main.erl
748+
-define(X, 1).
749+
-include("h.hrl").
750+
-define(X, 2).
751+
bar() -> ?~X.
752+
//- /src/h.hrl
724753
"#,
725754
2,
726755
);

0 commit comments

Comments
 (0)