@@ -120,80 +120,106 @@ warnUnusedImport uses (A.A region (name, _method)) =
121resolveExports
121resolveExports
122 :: [Var.Value]
122 :: [Var.Value]
123− -> Var.Listing Var.Value
123+ -> Var.Listing (A.Located Var.Value)
124 -> Result.ResultErr [Var.Value]
124 -> Result.ResultErr [Var.Value]
125resolveExports fullList (Var.Listing partialList open) =
125resolveExports fullList (Var.Listing partialList open) =
127 then Result.ok fullList
127 then Result.ok fullList
129 (\xs ys zs -> xs ++ ys ++ zs)
129 (\xs ys zs -> xs ++ ys ++ zs)
130− <$> getValueExports
130+ <$> T.traverse getValueExport values
131 <*> (concat <$> T.traverse getAliasExport aliases)
131 <*> (concat <$> T.traverse getAliasExport aliases)
132 <*> T.traverse getAdtExport adts
132 <*> T.traverse getAdtExport adts
134 (allValues, allAliases, allAdts) =
134 (allValues, allAliases, allAdts) =
135− splitValues fullList
135+ maybeUnzip3 (map splitValue fullList)
137 (values, aliases, adts) =
137 (values, aliases, adts) =
138− splitValues partialList
138+ maybeUnzip3 (map splitLocatedValue partialList)
140− getValueExports =
140+ allValuesSet = Set.fromList allValues
141− case Set.toList (Set.difference values' allValues') of
141+ adtTypes = map fst allAdts
142− [] -> Result.ok (map Var.Value values)
143− xs -> manyNotFound xs allValues
145− allValues' = Set.fromList allValues
146− values' = Set.fromList values
143+ getValueExport (A.A region name) =
144+ if Set.member name allValuesSet
145+ then Result.ok (Var.Value name)
146+ else manyNotFound region [name] allValues
148− getAliasExport alias
148+ getAliasExport (A.A region alias)
149 | alias `elem` allAliases =
149 | alias `elem` allAliases =
150− let recordConstructor =
150+ Result.ok $ (:) (Var.Alias alias) $
151− if alias `elem` allValues then [Var.Value alias] else []
151+ if alias `elem` allValues then [Var.Value alias] else []
153+ | List.elem alias adtTypes =
153− Result.ok (Var.Alias alias : recordConstructor)
154+ Result.ok [Var.Union alias (Var.Listing [] False)]
155 | otherwise =
156 | otherwise =
156− case List.find (\(name, _ctors) -> name == alias) allAdts of
157− Nothing -> manyNotFound [alias] allAliases
157+ manyNotFound region [alias] (allAliases ++ adtTypes)
158− Just (name, _ctor) ->
158+
159− Result.ok [Var.Union name (Var.Listing [] False)]
161− getAdtExport (name, Var.Listing ctors open) =
159+ getAdtExport (A.A region (name, Var.Listing ctors open)) =
162− case lookup name allAdts of
160+ case List.lookup name allAdts of
163− Nothing -> manyNotFound [name] (map fst allAdts)
162+ manyNotFound region [name] adtTypes
164 Just (Var.Listing allCtors _)
164 Just (Var.Listing allCtors _)
165 | open ->
165 | open ->
166 Result.ok (Var.Union name (Var.Listing allCtors False))
166 Result.ok (Var.Union name (Var.Listing allCtors False))
167 | otherwise ->
167 | otherwise ->
168 case filter (`notElem` allCtors) ctors of
168 case filter (`notElem` allCtors) ctors of
169− [] -> Result.ok (Var.Union name (Var.Listing ctors False))
170+ Result.ok (Var.Union name (Var.Listing ctors False))
170− unfoundCtors -> manyNotFound unfoundCtors allCtors
172+ manyNotFound region unfoundCtors allCtors
172− manyNotFound nameList possibilities =
174+ manyNotFound region nameList possibilities =
173− Result.errors (map (notFound possibilities) nameList)
175+ Result.errors (map (notFound region possibilities) nameList)
175− notFound possibilities name =
177+ notFound region possibilities name =
176− A.A undefined $ CError.Export name $
178+ A.A region $ CError.Export name $
177 CError.nearbyNames id name possibilities
179 CError.nearbyNames id name possibilities
180−splitValues
182+-- GROUPING VALUES
182− -> ([String], [String], [(String, Var.Listing String)])
184+maybeUnzip3 :: [(Maybe a, Maybe b, Maybe c)] -> ([a],[b],[c])
183−splitValues mixedValues =
185+maybeUnzip3 tuples =
184− case mixedValues of
186+ let (as, bs, cs) = unzip3 tuples
185− [] -> ([], [], [])
187+ in
186− x:xs ->
188+ (Maybe.catMaybes as, Maybe.catMaybes bs, Maybe.catMaybes cs)
187− let (values, aliases, adts) = splitValues xs in
189+
193+ -> ( Maybe String, Maybe String, Maybe (String, Var.Listing String) )
188− case x of
195+ case value of
189− Var.Value name ->
196+ Var.Value name ->
190− (name : values, aliases, adts)
197+ (Just name, Nothing, Nothing)
200+ (Nothing, Just name, Nothing)
192− Var.Alias name ->
202+ Var.Union name listing ->
193− (values, name : aliases, adts)
203+ (Nothing, Nothing, Just (name, listing))
207+ :: A.Located Var.Value
209+ ( Maybe (A.Located String)
210+ , Maybe (A.Located String)
211+ , Maybe (A.Located (String, Var.Listing String))
213+splitLocatedValue (A.A region value) =
216+ (Just (A.A region name), Nothing, Nothing)
219+ (Nothing, Just (A.A region name), Nothing)
195− Var.Union name listing ->
221+ Var.Union name listing ->
196− (values, aliases, (name, listing) : adts)
222+ (Nothing, Nothing, Just (A.A region (name, listing)))
199-- DECLARATIONS
225-- DECLARATIONS