Skip to content

Compiler refuses to apply a converter when the input is an Array or Openarray #912

@ReneSac

Description

@ReneSac

Here an example where, depending how you use it, the converter works or fails:

See also: https://github.com/micklat/NimBorg/blob/master/nim_py/high_level.nim
(search for the line with: " # doesn't work as a converter, I don't know why ")

import opengl, glfw/glfw

type
  TCoord = enum
    x, y, z

  TVertex = object
    pos: array[TCoord, GLfloat]
    normal: array[TCoord, GLfloat]


var
  vertices: array[NumVertices, TVertex]  

converter toGlVec(a: Array[3, int]) : array[TCoord, GLfloat] = 
  return [a[x.ord].GlFloat, a[y.ord].GlFloat, a[z.ord].GlFloat]

# Call:
newVertexGroup([0, 0, 1] , [-1, -1, 1] , [1, -1, 1] , [1, 1, 1] , [-1, 1, 1] )

#Works:
proc newVertexGroup(normal: Array[3, int], pos: varargs[Array[3, int]]) =
  var curVertex {.global.} = 0
  for p in pos:
    vertices[curVertex] = TVertex(pos: p, normal: normal)
    curVertex.inc


#Fails:
proc newVertexGroup(normal: array[TCoord, GLfloat], pos: varargs[array[TCoord, GLfloat]]) =
  var curVertex {.global.} = 0
  for p in pos:
    vertices[curVertex] = TVertex(pos: p, normal: normal)
    curVertex.inc

# Error: type mismatch: got (Array constructor[0..2, int], Array constructor[0..2, int], Array constructor[0..2, int], Array constructor[0..2, int], Array constructor[0..2, int])
#but expected one of: 
#N.newVertexGroup(normal: array[TCoord, GLfloat], pos: varargs[array[TCoord, GLfloat]])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions