Skip to content

resem type section macros if output is not type section ast#25706

Open
metagn wants to merge 1 commit intonim-lang:develfrom
metagn:type-pragma-macro-resem
Open

resem type section macros if output is not type section ast#25706
metagn wants to merge 1 commit intonim-lang:develfrom
metagn:type-pragma-macro-resem

Conversation

@metagn
Copy link
Copy Markdown
Collaborator

@metagn metagn commented Apr 5, 2026

Type pragma macros are evaluated with efNoSemCheck which means the result node of the macro is left untyped and fed back to the type section statement to be semchecked later. This is important for mutually recursive type AST to work properly.

However only 1 layer of macro execution is a big limitation and makes some things impossible like optional typed args in the macro call or feeding to a typed macro as in #13830, #15334, #18864 and related issues. This is unless we wrap in nkStmtListType assigned to _ but this loses mutual recursion functionality.

Since any output that is not nkTypeDef or nkTypeSection is going to be rejected by the type section processor anyway, we allow these to be resemmed in case they are nodes calling into another macro that will produce a type section node. In the case that it does, the expression flag propagates and prevents semchecking for these nodes as well, allowing the type section to handle them properly. The nodes that get resemmed could be restricted to just the nodes that can produce type section AST like calls, but it is probably better to not be restrictive and makes sense just to mirror the "whitelisted" nodes in the type section processor.

Since any case affected by this was directly disallowed before, this is fully backwards compatible, and enables a substantial amount of uses for type pragma macros. So maybe this could be treated as a bugfix rather than a new feature and backported. Although other issues might come up with this that would also need backporting more fixes later, but it is not likely to require a revert or break code.

I can also add this to the manual but it would require an explanation of type section semchecking mechanics which is not already there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant