git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
psc-docs: Fix crash for certain kinds of reexports
2a915fdHarry Garrood
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 ::
159 (name, P.ModuleName) ->
159 (name, P.ModuleName) ->
160 m (P.ModuleName, name)
160 m (P.ModuleName, name)
161findImport imps (name, orig) =
161findImport imps (name, orig) =
162+ let
162− case filter (\(qual, mn) -> P.disqualify qual == name && mn == orig) imps of
163+ matches (qual, mn) = P.disqualify qual == name && mn == orig
163− [(P.Qualified (Just importedFrom) _, _)] ->
164+ matching = filter matches imps
164− pure (importedFrom, name)
165+ getQualified (P.Qualified mname _) = mname
165− other ->
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+ [] ->
166− internalErrorInModule ("findImport: unexpected result: " ++ show other)
174+ internalErrorInModule ("findImport: not found: " ++ show (name, orig))
167
175
168lookupValueDeclaration ::
176lookupValueDeclaration ::
169 (Applicative m,
177 (Applicative m,