Skip to content

Types declared in non-top-level scope gensym their symbols to workaround bad mangling #22571

@metagn

Description

@metagn

Description

macro foo(x: typed) =
  result = x
  echo result.repr

block: # or `proc main =`
  foo:
    type Foo = object
  echo Foo()

Nim Version

2.0.0

Current Output

type
  Foo_520093702 = object
(7, 8) Error: undeclared identifier: 'Foo'

Expected Output

type
  Foo = object
()

Possible Solution

Read comments below (#22571 (comment) and #22571 (comment)) for description of why this happens. The issue is caused by the compiler intentionally gensymming these types to workaround a codegen issue that should have been solved in codegen.

Additional Information

Works if the macro is called at top level, or with declarations that are not types like proc or const

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions