@@ -282,16 +282,18 @@ declarationsToPatches moduleName decls =
282 (Maybe.catMaybes maybeNodes, concat patchLists)
282 (Maybe.catMaybes maybeNodes, concat patchLists)
285−-- When canonicalizing, all _values should be Local, but all _adts and _patterns
285+-- When canonicalizing, it is important that:
286−-- should be fully namespaced. With _adts, they may appear in types that can
286+-- _adts are fully namespaced (Var.Module ...)
287−-- escape the module.
287+-- _patterns are fully namespaced (Var.Module ...)
288+-- _values that are defined as top-level declarations are (Var.TopLevel ...)
289+-- all other _values are local (Var.Local)
288declToPatches
290declToPatches
289 :: Module.Name
291 :: Module.Name
290 -> D.ValidDecl
292 -> D.ValidDecl
291 -> (Maybe Node, [Env.Patch])
293 -> (Maybe Node, [Env.Patch])
292declToPatches moduleName (A.A (region,_) decl) =
294declToPatches moduleName (A.A (region,_) decl) =
293− let local mkPatch x =
295+ let topLevel mkPatch x =
294− mkPatch x (Var.local x)
296+ mkPatch x (Var.topLevel moduleName x )
296 namespaced mkPatch x =
298 namespaced mkPatch x =
297 mkPatch x (Var.fromModule moduleName x)
299 mkPatch x (Var.fromModule moduleName x)
@@ -302,7 +304,7 @@ declToPatches moduleName (A.A (region,_) decl) =
302 case decl of
304 case decl of
303 D.Definition (Valid.Definition pattern _ _) ->
305 D.Definition (Valid.Definition pattern _ _) ->
304 ( Nothing
306 ( Nothing
305− , map (local Env.Value) (P.boundVarList pattern)
307+ , map (topLevel Env.Value) (P.boundVarList pattern)
308 D.Datatype name _ ctors ->
310 D.Datatype name _ ctors ->
@@ -310,7 +312,7 @@ declToPatches moduleName (A.A (region,_) decl) =
311 ( Nothing
313 ( Nothing
312 , namespaced Env.Union name
314 , namespaced Env.Union name
313− : map (local Env.Value) ctorNames
315+ : map (topLevel Env.Value) ctorNames
314 ++ map patternPatch ctors
316 ++ map patternPatch ctors
@@ -318,14 +320,14 @@ declToPatches moduleName (A.A (region,_) decl) =
318 ( Just (node region name tvars alias)
320 ( Just (node region name tvars alias)
319 , case alias of
321 , case alias of
320 A.A _ (Type.RRecord _ _) ->
322 A.A _ (Type.RRecord _ _) ->
321− [local Env.Value name]
323+ [topLevel Env.Value name]
326 D.Port port ->
328 D.Port port ->
327 ( Nothing
329 ( Nothing
328− , [local Env.Value (D.validPortName port)]
330+ , [topLevel Env.Value (D.validPortName port)]
331 D.Fixity _ _ _ ->
333 D.Fixity _ _ _ ->