Skip to content
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

Compilation error with ref type #11

Closed
Tormund opened this issue Sep 19, 2019 · 3 comments
Closed

Compilation error with ref type #11

Tormund opened this issue Sep 19, 2019 · 3 comments

Comments

@Tormund
Copy link

Tormund commented Sep 19, 2019

import json_serialization

type
    DummyRef* = ref object of RootObj
        a: float
var dr = new(DummyRef)
dr.a = 100225.00
echo "resref:\n\t", dr.toJson 

nim-stew\stew\shims\macros.nim(43, 28) Error: index 2 not in 0 .. -1

@zah
Copy link
Contributor

zah commented Nov 13, 2019

I've tried to investigate this and so far I'm hitting into insurmountable Nim issues in the behaviour of functions such as getType and getImpl. The issues seems to be affecting only types using the ref object short-cut. Everything is fine if you use the following approach instead:

import
  ../json_serialization

type
  DummyObj* = object of RootObj
    a: float

  DummyRef = ref DummyObj

var dr = new(DummyRef)
dr.a = 100225.00
echo "resref:\n\t", dr.toJson

@jangko
Copy link
Contributor

jangko commented Nov 14, 2019

nice, it works. I agree this is Nim compiler internal inconsistency.

@zah
Copy link
Contributor

zah commented Apr 9, 2020

This should now work fine in Nim >= 1.2

@zah zah closed this as completed Apr 9, 2020
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

No branches or pull requests

3 participants