Skip to content

Instantly share code, notes, and snippets.

@singularperturbation
Last active April 1, 2017 20:53
Show Gist options
  • Save singularperturbation/79d4e5fbc9dea5999ce4923dce5dd6d1 to your computer and use it in GitHub Desktop.
Save singularperturbation/79d4e5fbc9dea5999ce4923dce5dd6d1 to your computer and use it in GitHub Desktop.
Error with create / createShared in current devel (5fdd03ad4d2a) of Nim
type Foo = object
fooInt*: int
proc main() =
# Error: type mismatch: got (ptr Foo) but expected 'ptr None'
var f = create(Foo)
f.fooInt = 3
echo $f
discard realloc(f, 0)
var g = Foo()
g.fooInt = 3
echo $g
when isMainModule:
main()
@singularperturbation
Copy link
Author

I think the problem is with passing the typedesc as a proc parameter, if I use:

template localcreate[T]: ptr T = cast[ptr T](alloc0(sizeof(T)))

as a workaround then this will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment