git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
psc-docs: Fix crash for certain kinds of reexports

Fixes #1831: crashes in psc-docs and psc-publish when encountering modules which re-export declarations which were imported from more than one module. For example, if: * a module A defines and exports a value `foo` * another module B re-exports `foo` from A * C re-exports both A and B this would cause a crash. With this fix, we document `foo` as having been re-exported from whichever module out of A and B appears first in the Imports list from C's Env.

commit2a915fd1496b8011616f1529d5f7ab0d5066fe7b authorHarry Garrood <harry@garrood.me> dateMon 18 Jan 2016, 14:54 (11 years ago) parent1b948d0
2 files changed+40−5
examples/docs/src/ImportedTwice.purs+27 src/Language/PureScript/Docs/Convert/ReExports.hs+13−5
examples/docs/src/ImportedTwice.pursnew file+27
@@ -0,0 +1,27 @@
1+-- See also an example in the wild: purescript-transformers v0.8.4.
2+-- Control.Monad.RWS.Trans re-exports `lift` from both Control.Monad.Trans
3+-- (where it is originally defined) and Control.Monad.RWS.Class (which
4+-- re-exports it from Control.Monad.Trans).
5+
6+module ImportedTwice
7+ ( module A
8+ , module B
9+ )
10+ where
11+
12+import A
13+import B
14+
15+module A
16+ ( module B )
17+ where
18+
19+import B
20+
21+bar :: Int
22+bar = 1
23+
24+module B where
25+
26+foo :: Int
27+foo = 0
src/Language/PureScript/Docs/Convert/ReExports.hs+13−5
@@ -159,11 +159,19 @@ findImport ::
159159 (name, P.ModuleName) ->
160160 m (P.ModuleName, name)
161161findImport imps (name, orig) =
162− case filter (\(qual, mn) -> P.disqualify qual == name && mn == orig) imps of
163− [(P.Qualified (Just importedFrom) _, _)] ->
164− pure (importedFrom, name)
165− other ->
166− internalErrorInModule ("findImport: unexpected result: " ++ show other)
162+ let
163+ matches (qual, mn) = P.disqualify qual == name && mn == orig
164+ matching = filter matches imps
165+ getQualified (P.Qualified mname _) = mname
166+ in
167+ case mapMaybe (getQualified . fst) matching of
168+ -- A value can occur more than once if it is imported twice (eg, if it is
169+ -- exported by A, re-exported from A by B, and C imports it from both A
170+ -- and B). In this case, we just take its first appearance.
171+ (importedFrom:_) ->
172+ pure (importedFrom, name)
173+ [] ->
174+ internalErrorInModule ("findImport: not found: " ++ show (name, orig))
167175
168176lookupValueDeclaration ::
169177 (Applicative m,