The following is thrown off by the echo. Is there a way to make this work?
let format =
                if channels == 1:
                    TextureInternalFormat.RED
                elif channels == 3:
                    TextureInternalFormat.RGB
                elif channels == 4:
                    TextureInternalFormat.RGBA
                else:
                    echo "Texture Format Unknown, assuming RGB"
                    TextureInternalFormat.RGB
It might work if you convert that "if expression" over to a "case expression".
if expression docs:
https://nim-lang.org/docs/manual.html#statements-and-expressions-if-expression
case expression docs:
https://nim-lang.org/docs/manual.html#statements-and-expressions-case-expression
Looks like case expressions are a bit more flexible.
Another workaround would be - in the if expression, to call a function that does the echo, and then returns a value of the correct type.
I ninja-edited my earlier post with some other details.
I'm not sure why, but 'case expressions' and 'if expressions' are designed a bit differently to each other, and are documented that way.
I think perhaps it's something like "things that can be an expression" are mainly some specific special cases, and "case expressions" got more love than "if expressions".
Try submitting a feature request over on the issue tracker perhaps?
let channels = 7
let format =
  if channels == 1:
    1
  elif channels == 3:
    2
  elif channels == 4:
    3
  else:
    (echo "Texture Format Unknown, assuming RGB";
    4)
echo format
Texture Format Unknown, assuming RGB
4
And another:
let channels = 7
let format =
  if channels == 1:   1
  elif channels == 3: 2
  elif channels == 4: 3
  else: (block:
      echo "Texture Format Unknown, assuming RGB"
      4
    )
echo format