Skip to content

SIGSEGV on generic macro returning a type #8406

@Quelklef

Description

@Quelklef

The following SIGSEGVs:

macro f(x: static[int]): untyped = discard
proc g[X: static[int]](v: f(X)) = discard

This is valid with the type system, though, right? Since X is known at compile-time it can be used to generate a type for v? I want to do something like this:

type MyFancyConcreteType = ...
type MyFancyGenericType[N: static[int]] = ...

macro Choose(N: static[int]): untyped =
  if N == 2:
    return ident("MyFancyConcreteType")
  else:
    return nnkBracketExpr.newTree(ident("MyFancyGenericType"), newIntLitNode(N))

var x: Choose(2)  # of MyFancyConcreteType
var y: Choose(3)  # of MyFancyGenericType[3]

# Generic procs may still be written
proc doSomethingWithEither[N: static[int]](v: Choose(N)) = ...

Is this possible, SIGSEGV or no; should I abandon the idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions