diff options
9 files changed, 30 insertions, 1 deletions
diff --git a/compiler/GHC/Unit/Finder.hs b/compiler/GHC/Unit/Finder.hs index e722e432af..25d3f68d00 100644 --- a/compiler/GHC/Unit/Finder.hs +++ b/compiler/GHC/Unit/Finder.hs @@ -180,7 +180,10 @@ findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg = | otherwise = findHomePackageModule fc opts uid mod_name - any_home_import = foldr orIfNotFound home_import (map home_pkg_import other_fopts) + -- Do not be smart and change this to `foldr orIfNotFound home_import hs` as + -- that is not the same!! home_import is first because we need to look within ourselves + -- first before looking at the packages in order. + any_home_import = foldr1 orIfNotFound (home_import: map home_pkg_import other_fopts) pkg_import = findExposedPackageModule fc fopts units mod_name mb_pkg diff --git a/testsuite/tests/driver/multipleHomeUnits/all.T b/testsuite/tests/driver/multipleHomeUnits/all.T index d289a447a6..6b2ad64eb5 100644 --- a/testsuite/tests/driver/multipleHomeUnits/all.T +++ b/testsuite/tests/driver/multipleHomeUnits/all.T @@ -62,6 +62,9 @@ test('MHU_OptionsGHC', normal, compile_fail, ['']) test('multipleHomeUnits_loop', [extra_files([ 'a/', 'unitA', 'loop', 'unitLoop'])], multiunit_compile, [['unitA', 'unitLoop'], '-fhide-source-paths']) +# This test checks that we look for things in our home unit before looking in dependencies +test('multipleHomeUnits_import_order', [extra_files([ 'unitOrder1', 'unitOrder2', 'order-matters1', 'order-matters2'])], multiunit_compile, [['unitOrder1', 'unitOrder2'], '-fhide-source-paths']) + test('multipleHomeUnits_recomp', [copy_files,extra_files([ 'Recomp.hs', 'unitRecomp', 'unitDep', 'Dep.hs'])], makefile_test, []) test('multipleHomeUnits_recomp_th', [filter_stdout_lines(r'.*Compiling.*'), copy_files, extra_files(['thRecomp.script', 'unitRecompTH', 'unitDep', 'RecompTH.hs', 'Dep.hs', '../../ghci/shell.hs']) , extra_run_opts('-v1 -unit @unitRecompTH -unit @unitDep')], ghci_script, ['thRecomp.script']) diff --git a/testsuite/tests/driver/multipleHomeUnits/multipleHomeUnits_import_order.stderr b/testsuite/tests/driver/multipleHomeUnits/multipleHomeUnits_import_order.stderr new file mode 100644 index 0000000000..4358ec822b --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/multipleHomeUnits_import_order.stderr @@ -0,0 +1,4 @@ +[1 of 4] Compiling A[order-matters1] +[2 of 4] Compiling A[order-matters2] +[3 of 4] Compiling B[order-matters1] +[4 of 4] Compiling B[order-matters2] diff --git a/testsuite/tests/driver/multipleHomeUnits/order-matters1/A.hs b/testsuite/tests/driver/multipleHomeUnits/order-matters1/A.hs new file mode 100644 index 0000000000..a1934d7fab --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/order-matters1/A.hs @@ -0,0 +1,3 @@ +module A where + +a1 = () diff --git a/testsuite/tests/driver/multipleHomeUnits/order-matters1/B.hs b/testsuite/tests/driver/multipleHomeUnits/order-matters1/B.hs new file mode 100644 index 0000000000..413e95083a --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/order-matters1/B.hs @@ -0,0 +1,5 @@ +module B where + +import A + +foo = a1 diff --git a/testsuite/tests/driver/multipleHomeUnits/order-matters2/A.hs b/testsuite/tests/driver/multipleHomeUnits/order-matters2/A.hs new file mode 100644 index 0000000000..c1b1a23f67 --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/order-matters2/A.hs @@ -0,0 +1,3 @@ +module A where + +a2 = () diff --git a/testsuite/tests/driver/multipleHomeUnits/order-matters2/B.hs b/testsuite/tests/driver/multipleHomeUnits/order-matters2/B.hs new file mode 100644 index 0000000000..400c23723a --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/order-matters2/B.hs @@ -0,0 +1,6 @@ +module B where + +-- Refers to A from current unit +import A + +foo = a2 diff --git a/testsuite/tests/driver/multipleHomeUnits/unitOrder1 b/testsuite/tests/driver/multipleHomeUnits/unitOrder1 new file mode 100644 index 0000000000..2fd867cb08 --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/unitOrder1 @@ -0,0 +1 @@ +-i -iorder-matters1 A B -this-unit-id order-matters1 diff --git a/testsuite/tests/driver/multipleHomeUnits/unitOrder2 b/testsuite/tests/driver/multipleHomeUnits/unitOrder2 new file mode 100644 index 0000000000..44ee993a07 --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/unitOrder2 @@ -0,0 +1 @@ +-i -iorder-matters2 A B -package-id order-matters1 -this-unit-id order-matters2 |