godot-nim icon indicating copy to clipboard operation
godot-nim copied to clipboard

Error when exporting `seq[T]`

Open arunvickram opened this issue 4 years ago • 2 comments

I'm running into an issue where I have an object subclassing a resource:

import godot
import godotapi/resource
import source/party/skill

type SkillsList = seq[Skill]

gdobj Job of Resource:
  var jobName* {.gdExport.}: string = ""
  var skills* {.gdExport.}: seq[string] = @[ ]

The error I'm getting is:

nim/godotnim.nim(769, 9) Error: type mismatch: got <typeof(nil)> but expected 'seq[string]'

I looked into it and it's referencing this proc:

proc fromVariant*[T](s: var seq[T], val: Variant): ConversionResult =
  if val.getType() == VariantType.Nil:
    s = nil
  elif val.getType() == VariantType.Array:
    let arr = val.asArray()
    var newS = newSeq[T](arr.len)
    for idx, item in arr:
      mixin fromVariant
      let convResult = fromVariant(newS[idx], item)
      if convResult != ConversionResult.OK:
        return convResult
    shallowCopy(s, newS)
  else:
    result = ConversionResult.TypeError

and the line it's through an error on is the s = nil. I'm not sure how gdobj gets to the point where it assumes that val is VariantType.Nil, but that seems to be causing the issue.

arunvickram avatar Dec 30 '20 20:12 arunvickram

Did you manage to fix it? I'm having the same problem exactly. I know it's a very old issue but I'm lost.

Xzayler avatar Jul 11 '22 21:07 Xzayler

I haven't yet, I just moved on

arunvickram avatar Sep 14 '22 22:09 arunvickram