Skip to content

Make defaults work on generic types #14

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Patitotective
Copy link
Contributor

Trying to solve #13.
Here's an example proving that it should work:

import std/[macros, genasts]

macro doIt(impl: untyped): untyped =
  result = impl
  result[^1] = genast():
    type Bleh[T] = object
      x: T
    proc initBleh[T](): Bleh[T] = Bleh[T](x: 100)
    Bleh

type MyType {.doIt.} = object

echo initBleh[int]()

Though right now, the code below fails:

import constructor/defaults

type
  Thingy[T] {.defaults: {}.} = object
    c: T = 1

echo initThingy[int]()

With:

$ nim c --expandMacro:defaults trial.nim
..................................................................................................
.../trial.nim(4, 15) Hint: expanded macro: Thingy[T] {..} =
  type
    Inner_536871044[T] = object
    
  proc initThingy[T](): Inner_536871044[T] =
    Inner_536871044[T](c: 1)
  
  Inner_536871044 [ExpandMacro]
..../src/constructor/defaults.nim(63, 22) Hint: 'initThingy' is declared but not used [XDeclaredButNotUsed]
.../trial.nim(7, 6) Error: undeclared identifier: 'initThingy'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (5, 1): 'Thingy'

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