From d87bfe207d6af0ff1a4aa4b355dd1b687f509945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= Date: Sun, 8 Mar 2026 21:31:09 +0200 Subject: [PATCH] Fix `-include` header when known modules are used Currently if you have a.h with: ``` #include ``` And empty `b.h` then `-include` fails: ``` $ dstep -includeb.h a.h dstep: an unknown error occurred: core.exception.RangeError@dstep/translator/HeaderIndex.d(100): Range violation ``` This commit fixes this issue. --- dstep/translator/HeaderIndex.d | 4 ++++ tests/functional/graph/include_known.h | 1 + tests/unit/IncludeGraphTests.d | 11 +++++++++++ 3 files changed, 16 insertions(+) create mode 100644 tests/functional/graph/include_known.h diff --git a/dstep/translator/HeaderIndex.d b/dstep/translator/HeaderIndex.d index ae1b2531..78ee27c7 100644 --- a/dstep/translator/HeaderIndex.d +++ b/dstep/translator/HeaderIndex.d @@ -68,6 +68,10 @@ class IncludeGraph auto pair = Inclusion(headers_[includedPath], headers_[path]); directInclusions.add(pair); + } else if (includedPath != "" && includedPath !in headers_) + { + reverse_[headers_.length] = includedPath; + headers_[includedPath] = headers_.length; } } diff --git a/tests/functional/graph/include_known.h b/tests/functional/graph/include_known.h new file mode 100644 index 00000000..339f4fc1 --- /dev/null +++ b/tests/functional/graph/include_known.h @@ -0,0 +1 @@ +#include diff --git a/tests/unit/IncludeGraphTests.d b/tests/unit/IncludeGraphTests.d index 8fcf78e5..ef37d832 100644 --- a/tests/unit/IncludeGraphTests.d +++ b/tests/unit/IncludeGraphTests.d @@ -90,3 +90,14 @@ unittest new HeaderIndex(translationUnit); } + +unittest +{ + const string file = "tests/functional/graph/subfile1.h".asAbsNormPath(); + + auto translationUnit = makeTranslationUnit( + "tests/functional/graph/include_known.h", + ["-Wno-missing-declarations", "-Itests/functional", "-include", file]); + + new HeaderIndex(translationUnit); +}