nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.

Home Page:https://nim-works.github.io/nimskull/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

set[int8] cannot initialized with values

blackmius opened this issue · comments

Example

var a: set[int8] = {1}
var b: set[uint8] = {1}

Actual Output

Error: type mismatch: got 'set[range 0..65535(int)]' for '{1}' but expected 'set[int8]'

Expected Output

compiled

Workaround

var a: set[int8] = {1.int8}

I believe you meant set[int8] rather than seq[int8]? If so, could you update the title and body?

As as an aside, you can also use 1'i8 instead of 1.int8 (it's a bit shorter).

sure seq -> set, sorry for confusion

The examples in the body are still wrong, as in those should definitely be type errors; since you're attempting to assign a set to a sequence. The work around is confusing, is there a converter at play there because it would not work?

this is more related to integer literals inference which most time inference to int and don't respect other int/uint types.
other error examples:

const
  my_array: array[4, int8] = [1, 1, 1, 1]
  my_tuple: tuple[x, y: int8] = (1, 1)

var
  x: int32
  y: int32

x = 1 shl x
y = 1 shr y
Error: type mismatch: got 'array[0..3, int]' for '[1, 1, 1, 1]' but expected 'array[0..3, int8]'
Error: type mismatch: got '(int, int)' for '(1, 1)' but expected 'tuple[x: int8, y: int8]'
Error: type mismatch: got 'int' for '1 shl x' but expected 'int32'
Error: type mismatch: got 'int' for '1 shr y' but expected 'int32'