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

inline structural/alias invocations even with generic arguments, broken #335

Closed
wants to merge 2 commits into from

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Jan 6, 2025

In:

type
  NodeObj[T] = object
    x: Node[T]
  Node[T] = ref NodeObj[T]

first SemcheckTopLevelSyms will save the untyped AST of the types to their symbols, however they will not define typevars or look them up in the body. This means when NodeObj is being semchecked, attempting to inline Node[T] by instantiating it will not work because there will be no typevars to replace.

This is a general problem for forwarded generic types:

type
  Foo[T] = object
    x: Bar[int]
  Bar[T] = object

A solution might be to define the typevars in the SemcheckTopLevelSyms pass and use an untyped prepass on the body so that they can be instantiated. But this is not done yet as an untyped prepass is not implemented.

The original reason for this PR was that the Node[T]() object constructor syntax/dotfields etc in generics don't work without it, but there is another solution which is just recursively skipping ref/invocations.

@metagn
Copy link
Collaborator Author

metagn commented Jan 7, 2025

Can reopen when ready

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