Skip to content

Commit 499a03e

Browse files
authored
fix: don't hang on module expansions (#1340)
1 parent 320bc67 commit 499a03e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Expand.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ expand eval ctx xobj =
4141
Lst _ -> expandList xobj
4242
Arr _ -> expandArray xobj
4343
Sym _ _ -> expandSymbol xobj
44+
-- This case is needed to ensure we expand naked mod names to initers consistently.
45+
-- Consider both:
46+
-- (width (address &(B 2)))
47+
-- (width B)
48+
-- The first case is correct code and was handled by expandList. The second case is an error and previously resulted in a loop because
49+
-- module expansion wasn't handled in expandSymbol, but handling it there
50+
-- by ending the expansion loop breaks init expansion in the first case,
51+
-- since expandList calls expand.
52+
-- So, we have no choice but to add a case here to cut the recursion and to expand this form consistently in all places.
53+
Mod e _ ->
54+
let pathToModule = pathToEnv e
55+
implicitInit = XObj (Sym (SymPath pathToModule "init") Symbol) (xobjInfo xobj) (xobjTy xobj)
56+
in pure (ctx, Right implicitInit)
4457
_ -> pure (ctx, Right xobj)
4558
where
4659
expandList :: XObj -> IO (Context, Either EvalError XObj)

src/Primitives.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ primitiveRegisterType _ ctx [XObj (Sym (SymPath [] t) _) _ _] =
228228
primitiveRegisterTypeWithoutFields ctx t Nothing
229229
primitiveRegisterType _ ctx [x] =
230230
pure (evalError ctx ("`register-type` takes a symbol, but it got " ++ pretty x) (xobjInfo x))
231+
primitiveRegisterType _ ctx [x@(XObj (Sym (SymPath [] _) _) _ _), XObj (Str "") _ _] =
232+
pure (evalError ctx ("cannot register type " ++ pretty x ++ " with an empty string override, this will produce invalid C") (xobjInfo x))
231233
primitiveRegisterType _ ctx [XObj (Sym (SymPath [] t) _) _ _, XObj (Str override) _ _] =
232234
primitiveRegisterTypeWithoutFields ctx t (Just override)
233235
primitiveRegisterType _ ctx [x@(XObj (Sym (SymPath [] t) _) _ _), XObj (Str override) _ _, members] =

0 commit comments

Comments
 (0)