Skip to content

generic problem with static parameter #25099

@hamidb80

Description

@hamidb80

Nim Version

Nim Compiler Version 2.2.4 [Linux: amd64]
Compiled at 2025-04-22
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: f7145dd
active boot switches: -d:release

Description

the code works in play.nim-lang.org with the latest version and also older versions, but not on my machine

import std/random

func mods[T: static Natural](a: int, b: type T): range[0 .. T-1] =
  cast[type result](a mod b.int)

let  n = rand 0 .. 100
case n.mods 4
of 3,2,1: echo "huh"
of 0    : echo "got you"

Current Output

play.nim(7, 7) template/generic instantiation of `mods` from here
play.nim(3, 11) Error: cannot instantiate: 'T'

Expected Output

compiles successfully

Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions