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

Range checks are being ignored in template arguments #12780

Open
johnnovak opened this issue Nov 30, 2019 · 0 comments
Open

Range checks are being ignored in template arguments #12780

johnnovak opened this issue Nov 30, 2019 · 0 comments
Labels

Comments

@johnnovak
Copy link
Contributor

Range checks are being ignored in template arguments, e.g. range and Natural, as shown below,

Example

template testTemplate1(i: range[0..5]) =
  echo i

type Range = range[0..5]

template testTemplate2(i: Range) =
  echo i

template testTemplate3(i: Natural) =
  echo i

proc testProc(i: Range) =
  echo i

testTemplate1(100)   # Incorrect, prints 100
testTemplate2(100)   # Incorrect, prints 100
testTemplate3(-1)    # Incorrect, prints -1
#testProc(100)  # Correct, raises expected error:
                #   Error: conversion from int literal(100) to Range is invalid

Current Output

100
100
-1

Expected Output

All three template invocations should fail with an error, similarly to the proc call.

Additional Information

$ nim -v
Nim Compiler Version 1.0.4 [Windows: amd64]
Compiled at 2019-11-27
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: c8998c498f5e2a0874846eb31309e1d1630faca6
active boot switches: -d:release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants