@@ -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− 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
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.
172+ pure (importedFrom, name)
166− internalErrorInModule ("findImport: unexpected result: " ++ show other)
174+ internalErrorInModule ("findImport: not found: " ++ show (name, orig))
168lookupValueDeclaration ::
176lookupValueDeclaration ::
169 (Applicative m,
177 (Applicative m,