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

Static ranges are not checked #16969

Open
exelotl opened this issue Feb 8, 2021 · 0 comments
Open

Static ranges are not checked #16969

exelotl opened this issue Feb 8, 2021 · 0 comments

Comments

@exelotl
Copy link
Contributor

exelotl commented Feb 8, 2021

Example 1

Static range as a proc parameter:

proc foo(n: static[1..50]) =
  echo n

foo(1)
foo(0)
foo(999)

Current Output:

1
0
999

Expected Output:

Program fails to compile, giving a message such as
Error: conversion from int literal(0) to static[range 1..50(int)] is invalid

Example 2

Static range in a generic type:

type TileData[Size: static[5..99]] = object
  tiles: array[Size, uint8]

var t: TileData[-3]
echo t.tiles.len

Current Output:

-3

Expected Output:

Program fails to compile. The compiler should complain that a TileData was declared with a Size outside the range of 5..99

Additional information

$ nim -v
Nim Compiler Version 1.4.2 [Windows: amd64]
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