Skip to content

Cannot explicitly instantiate generic templates and macros with static parameters #9040

@timotheecour

Description

@timotheecour
  • proc allows calling proc fun*[N: static int](): auto = with fun[2] but not macro or template
  • case2b is fishy as N:int syntax accepts both 2 and int
import std/macros

when defined(case1):
  # Error: type expected
  macro fun*[N: static int](): untyped =
    # 1 # original bug report
    newLit 1 # EDIT

  const a = fun[2]()

when defined(case2):
  # compiles: ok
  proc fun*[N: static int](): auto =
    1
  const a = fun[2]()

when defined(case2b):
  # compiles, but this exposes an ambiguity in `N:int` syntax as it accepts both 2 and int
  proc fun*[N: int](): auto =
    1
  const a = fun[2]()
  const a2 = fun[int]()

when defined(case3):
  # Error: type expected
  template fun*[N: static int](): untyped =
    1
  const a = fun[2]()

when defined(case3b):
  # Error: type expected
  template fun*[N: int](): untyped =
    1
  const a = fun[2]()

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