@@ -282,7 +282,9 @@ declarationsToPatches moduleName decls =
282282 (Maybe.catMaybes maybeNodes, concat patchLists)
283283
284284
285−-- When canonicalizing, all _values should be Local, but all _adts and _patterns
285+-- When canonicalizing, all _values should be Local, except for top-level definitions but all
286+-- For _adts and _patterns,
287+-- we assume constructors are top-evel
286288-- should be fully namespaced. With _adts, they may appear in types that can
287289-- escape the module.
288290declToPatches
@@ -290,8 +292,11 @@ declToPatches
290292 -> D.ValidDecl
291293 -> (Maybe Node, [Env.Patch])
292294declToPatches moduleName (A.A (region,_) decl) =
293− let local mkPatch x =
294− mkPatch x (Var.local x)
295+ let --local mkPatch x =
296+ -- mkPatch x (Var.local x)
297+
298+ topLevel mkPatch x =
299+ mkPatch x (Var.topLevel moduleName x )
295300
296301 namespaced mkPatch x =
297302 mkPatch x (Var.fromModule moduleName x)
@@ -302,7 +307,7 @@ declToPatches moduleName (A.A (region,_) decl) =
302307 case decl of
303308 D.Definition (Valid.Definition pattern _ _) ->
304309 ( Nothing
305− , map (local Env.Value) (P.boundVarList pattern)
310+ , map (topLevel Env.Value) (P.boundVarList pattern)
306311 )
307312
308313 D.Datatype name _ ctors ->
@@ -310,7 +315,7 @@ declToPatches moduleName (A.A (region,_) decl) =
310315 in
311316 ( Nothing
312317 , namespaced Env.Union name
313− : map (local Env.Value) ctorNames
318+ : map (topLevel Env.Value) ctorNames
314319 ++ map patternPatch ctors
315320 )
316321
@@ -318,14 +323,14 @@ declToPatches moduleName (A.A (region,_) decl) =
318323 ( Just (node region name tvars alias)
319324 , case alias of
320325 A.A _ (Type.RRecord _ _) ->
321− [local Env.Value name]
326+ [topLevel Env.Value name]
322327 _ ->
323328 []
324329 )
325330
326331 D.Port port ->
327332 ( Nothing
328− , [local Env.Value (D.validPortName port)]
333+ , [topLevel Env.Value (D.validPortName port)]
329334 )
330335
331336 D.Fixity _ _ _ ->