Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type section typed AST does not retain postfix node #22933

Closed
Mycsina opened this issue Nov 13, 2023 · 4 comments · Fixed by #23096
Closed

Type section typed AST does not retain postfix node #22933

Mycsina opened this issue Nov 13, 2023 · 4 comments · Fixed by #23096

Comments

@Mycsina
Copy link

Mycsina commented Nov 13, 2023

Description

Using expandMacros only displays the * character on object fields.

expandMacros:
    type
        A* = object
            a*: int
        B = object
            b: int
    proc foo*(bar: int): string =
        return "baz"

I also tried adding a echo repr(n) to the toStrLit function that expandMacros uses but the output was the same.

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-11-11
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 52784f3
active boot switches: -d:release

Current Output

type
  A = object
    a*: int

  B = object
    b: int

proc foo(bar: int): string =
  return "baz"

iterator foo2(bar2: int): string =
  yield "baz"

Expected Output

type
  A* = object
    a*: int

  B = object
    b: int

proc foo*(bar: int): string =
  return "baz"

iterator foo2*(bar2: int): string =
  yield "baz"

Possible Solution

None

Additional Information

Versions 2.0.0 and 1.6.6 gave the same output.

@metagn
Copy link
Collaborator

metagn commented Nov 15, 2023

Typed AST of type sections do not retain the postfix nodes on the LHS (just becomes nnkSym), not a rendering problem, can confirm with macro foo(a: typed) = echo a.treeRepr

@Mycsina
Copy link
Author

Mycsina commented Nov 17, 2023

Oh okay, thought it might be a bug instead. Closing the issue then.

@Mycsina Mycsina closed this as completed Nov 17, 2023
@metagn
Copy link
Collaborator

metagn commented Nov 17, 2023

Did not mean it was intended behavior, sorry.

@metagn metagn reopened this Nov 17, 2023
@metagn metagn changed the title expandMacros doesn't display all nnkPostfixnodes properly Type section typed AST does not retain postfix node Nov 22, 2023
@elcritch
Copy link
Contributor

Ran into this issue as well. It's annoying because you think you've screwed up the template or macros.

metagn added a commit to metagn/Nim that referenced this issue Dec 18, 2023
Vindaar pushed a commit to SciNim/Unchained that referenced this issue Dec 20, 2023
`resolveTypeFromDistinct` calls `getImpl` on the distinct type which yields an `nkTypeDef` node of the original distinct type declaration, and returns the first child of the node, what would normally be the type name.

Normally when a type is exported its name in the AST becomes an `nkPostfix` node, however due to a [Nim bug](nim-lang/Nim#22933) this node was not saved in typed AST and the first child was always the type symbol node. If the bug in Nim is fixed, `resolveTypeFromDistinct` has to skip the postfix node here.
metagn added a commit to metagn/Nim that referenced this issue Dec 20, 2023
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 a pull request may close this issue.

3 participants