nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.58k stars 1.47k forks source link

Generics: type mismatch with multi-range types #7447

Open mratsim opened 6 years ago

mratsim commented 6 years ago

In the Generics type mismatch series #7432 and #7446

type HexChars = range['0'..'9'] or range['A'..'F'] or range['a'..'f']

proc foo(x: HexChars) = discard

let a = '0'

foo(a)
Error: type mismatch: got <char>
but expected one of:
proc foo(x: HexChars)

expression: foo(a)

I'm not sure range can be used like that but there should be an error message "you cannot combine Generics with ranges" in case it's not supposed to work like that.

metagn commented 1 month ago

Now this compiles but there is no error if you do let x = 'z'; foo(x), not even runtime, due to #4858 etc