Skip to content

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