Skip to content

VM does not support 'cast' from tySet to tyInt #22547

Open
@ASVIEST

Description

@ASVIEST

Description

type Bit {.pure.} = enum
  A
  B

static:
  echo cast[int]({A, B})

Nim Version

Nim Compiler Version 2.0.0 [Android: arm64] Compiled at 2023-08-01
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: a488067 active boot switches: -d:release -d:danger

Current Output

Error: VM does not support 'cast' from tySet to tyInt

Expected Output

3

Possible Solution

Add opcCastSetToInt(opcCastSetToInt32, opcCastSetToInt64) opcodes to vmdef and impl it in vm

Additional Information

simple vm workaround:

var bitmask = 0
for i in mySet:
  bitmask += 1 shl i.ord

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureVMsee also `const` labelconst`const x=expr` or `static: stmt`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions