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

enum error #19

Closed
geohuz opened this issue Aug 14, 2021 · 1 comment
Closed

enum error #19

geohuz opened this issue Aug 14, 2021 · 1 comment

Comments

@geohuz
Copy link

geohuz commented Aug 14, 2021

with the proto spec:

type
    TOPIC* {.pure.} = enum
        UNKNOWN = 0
        PARSER = 1
        CONNECTION = 2
        AUTH = 3
        EVENT = 4
        RECORD = 5
        RPC = 6
        PRESENCE = 7
        MONITORING = 8
        CLUSTER = 9
        LOCK = 10
        STATE_REGISTRY = 11
        ERROR = 100
    DPSMessage* = ref DPSMessageObj
    DPSMessageObj* = object of Message
        topic: TOPIC
        message: seq[byte]

The compiler generate the following errors:

/Users/geohuz/Coding/nimlearn/deepstream.io-protobuf/proto_files/general_pb.nim(120, 33) template/generic instantiation of `toJson` from here
/Users/geohuz/.nimble/pkgs/nimpb-0.2.0/nimpb/json.nim(42, 18) template/generic instantiation of `items` from here
/Users/geohuz/.choosenim/toolchains/nim-1.4.8/lib/system/iterators.nim(87, 19) template/generic instantiation of `..` from here
/Users/geohuz/.choosenim/toolchains/nim-1.4.8/lib/system/iterators_1.nim(85, 12) Error: type mismatch: got <TOPIC>
but expected one of: 
proc inc[T: Ordinal](x: var T; y = 1)
  first type mismatch at position: 1
  required type for x: var T: Ordinal
  but expression 'res' is of type: TOPIC

expression: inc(res)
@geohuz
Copy link
Author

geohuz commented Aug 14, 2021

It can be caused by change in nim-lang/Nim#14001, the following change as suggested:

proc toJson*[Enum: enum](value: Enum): JsonNode =
    for v in Enum.low.int..Enum.high.int:
        if ord(value) == v:
            return %($v)
    # The enum has a value that is not defined in the enum type
    result = %(cast[int](value))

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

1 participant