@@ -282,7 +282,9 @@ 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, all _values should be Local, except for top-level definitions but all
286+-- For _adts and _patterns,
287+-- we assume constructors are top-evel
286-- should be fully namespaced. With _adts, they may appear in types that can
288-- should be fully namespaced. With _adts, they may appear in types that can
287-- escape the module.
289-- escape the module.
288declToPatches
290declToPatches
@@ -290,8 +292,11 @@ declToPatches
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) =
295+ let --local mkPatch x =
296+ -- mkPatch x (Var.local x)
293− let local mkPatch x =
298+ topLevel mkPatch x =
294− mkPatch x (Var.local x)
299+ mkPatch x (Var.topLevel moduleName x )
296 namespaced mkPatch x =
301 namespaced mkPatch x =
297 mkPatch x (Var.fromModule moduleName x)
302 mkPatch x (Var.fromModule moduleName x)
@@ -302,7 +307,7 @@ declToPatches moduleName (A.A (region,_) decl) =
302 case decl of
307 case decl of
303 D.Definition (Valid.Definition pattern _ _) ->
308 D.Definition (Valid.Definition pattern _ _) ->
304 ( Nothing
309 ( Nothing
305− , map (local Env.Value) (P.boundVarList pattern)
310+ , map (topLevel Env.Value) (P.boundVarList pattern)
308 D.Datatype name _ ctors ->
313 D.Datatype name _ ctors ->
@@ -310,7 +315,7 @@ declToPatches moduleName (A.A (region,_) decl) =
311 ( Nothing
316 ( Nothing
312 , namespaced Env.Union name
317 , namespaced Env.Union name
313− : map (local Env.Value) ctorNames
318+ : map (topLevel Env.Value) ctorNames
314 ++ map patternPatch ctors
319 ++ map patternPatch ctors
@@ -318,14 +323,14 @@ declToPatches moduleName (A.A (region,_) decl) =
318 ( Just (node region name tvars alias)
323 ( Just (node region name tvars alias)
319 , case alias of
324 , case alias of
320 A.A _ (Type.RRecord _ _) ->
325 A.A _ (Type.RRecord _ _) ->
321− [local Env.Value name]
326+ [topLevel Env.Value name]
326 D.Port port ->
331 D.Port port ->
327 ( Nothing
332 ( Nothing
328− , [local Env.Value (D.validPortName port)]
333+ , [topLevel Env.Value (D.validPortName port)]
331 D.Fixity _ _ _ ->
336 D.Fixity _ _ _ ->