From eea99d6fae537502440cee4dde09c35e7284407c Mon Sep 17 00:00:00 2001 From: k-hara Date: Fri, 14 Jun 2013 12:38:40 +0900 Subject: [PATCH] fix Issue 10354 - DIP37: ICE with using indirectly imported template through package.d --- src/import.c | 4 ++-- test/compilable/extra-files/pkgDIP37_10354/mbar.d | 2 ++ test/compilable/extra-files/pkgDIP37_10354/mfoo.d | 2 ++ test/compilable/extra-files/pkgDIP37_10354/package.d | 3 +++ test/compilable/testDIP37_10354.d | 11 +++++++++++ 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/compilable/extra-files/pkgDIP37_10354/mbar.d create mode 100644 test/compilable/extra-files/pkgDIP37_10354/mfoo.d create mode 100644 test/compilable/extra-files/pkgDIP37_10354/package.d create mode 100644 test/compilable/testDIP37_10354.d diff --git a/src/import.c b/src/import.c index 9b1b9777b2b5..a5117e147bfd 100644 --- a/src/import.c +++ b/src/import.c @@ -166,10 +166,10 @@ void Import::load(Scope *sc) { dst->insert(id, mod); // id may be different from mod->ident, // if so then insert alias - if (!mod->importedFrom) - mod->importedFrom = sc ? sc->module->importedFrom : Module::rootModule; } } + if (mod && !mod->importedFrom) + mod->importedFrom = sc ? sc->module->importedFrom : Module::rootModule; if (!pkg) pkg = mod; diff --git a/test/compilable/extra-files/pkgDIP37_10354/mbar.d b/test/compilable/extra-files/pkgDIP37_10354/mbar.d new file mode 100644 index 000000000000..8fced25afba3 --- /dev/null +++ b/test/compilable/extra-files/pkgDIP37_10354/mbar.d @@ -0,0 +1,2 @@ +module pkgDIP37_10354.mbar; +void bar(T)() {} diff --git a/test/compilable/extra-files/pkgDIP37_10354/mfoo.d b/test/compilable/extra-files/pkgDIP37_10354/mfoo.d new file mode 100644 index 000000000000..7cd7c8bc2502 --- /dev/null +++ b/test/compilable/extra-files/pkgDIP37_10354/mfoo.d @@ -0,0 +1,2 @@ +module pkgDIP37_10354.mfoo; +void foo(T)() {} diff --git a/test/compilable/extra-files/pkgDIP37_10354/package.d b/test/compilable/extra-files/pkgDIP37_10354/package.d new file mode 100644 index 000000000000..9852eddba31e --- /dev/null +++ b/test/compilable/extra-files/pkgDIP37_10354/package.d @@ -0,0 +1,3 @@ +module pkgDIP37_10354; +public import pkgDIP37_10354.mfoo; +public import pkgDIP37_10354.mbar; diff --git a/test/compilable/testDIP37_10354.d b/test/compilable/testDIP37_10354.d new file mode 100644 index 000000000000..97b0f727958f --- /dev/null +++ b/test/compilable/testDIP37_10354.d @@ -0,0 +1,11 @@ +// PERMUTE_ARGS: +// REQUIRED_ARGS: -o- -Icompilable/extra-files + +module testDIP37_10354; +import pkgDIP37_10354.mfoo; +void main() +{ + import pkgDIP37_10354; + foo!string(); // OK + bar!string(); // OK <- ICE +}