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

Random: proc rand(x: HSlice) requires substraction #7698

Closed
mratsim opened this issue Apr 27, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@mratsim
Copy link
Collaborator

commented Apr 27, 2018

Currently it is not possible to use rand with slices of char or enum:

import random

let slice = '0'..'F'
let r = rand(cslice)
Error: type mismatch: got <char, char>
but expected one of:
proc `-`[T](x, y: set[T]): set[T]
...
type
  Op = enum
    Halt
    Inc
    Dec

import random

let opslice = Halt..Dec
let op = rand(opslice)

Same error

@Araq

This comment has been minimized.

Copy link
Member

commented Apr 27, 2018

But if we support enum the code could produce invalid values for enums with holes.

@mratsim

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 27, 2018

Then I think the signature should be T: SomeInteger.

@Araq

This comment has been minimized.

Copy link
Member

commented Apr 27, 2018

Fine with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.