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

set[int8] cannot initialized with values #1256

Open
blackmius opened this issue Mar 28, 2024 · 4 comments
Open

set[int8] cannot initialized with values #1256

blackmius opened this issue Mar 28, 2024 · 4 comments

Comments

@blackmius
Copy link

blackmius commented Mar 28, 2024

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}
@zerbina
Copy link
Collaborator

zerbina commented Mar 28, 2024

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).

@blackmius blackmius changed the title seq[int8] cannot initialized with values set[int8] cannot initialized with values Mar 28, 2024
@blackmius
Copy link
Author

sure seq -> set, sorry for confusion

@saem
Copy link
Collaborator

saem commented Mar 28, 2024

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?

@mrgaturus
Copy link
Contributor

mrgaturus commented Apr 1, 2024

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'

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

4 participants