Skip to content

Make defaults work on generic types - #14

Open
Patitotective wants to merge 1 commit into
beef331:masterfrom
Patitotective:master
Open

Make defaults work on generic types#14
Patitotective wants to merge 1 commit into
beef331:masterfrom
Patitotective:master

Conversation

@Patitotective

Copy link
Copy Markdown
Contributor

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

import std/[macros, genasts]
macrodoIt(impl: untyped): untyped=result= impl
result[^1] =genast():
typeBleh[T] =object
x: T
procinitBleh[T](): Bleh[T] =Bleh[T](x: 100)
BlehtypeMyType {.doIt.} =objectechoinitBleh[int]()

Though right now, the code below fails:

import constructor/defaults
typeThingy[T] {.defaults: {}.} =object
c: T =1echoinitThingy[int]()

With:

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

Sign up for freeto 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

@Patitotective