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 bounds in generics do not always compile #1771

Closed
gmpreussner opened this issue Dec 23, 2014 · 3 comments · Fixed by #22564
Closed

Range bounds in generics do not always compile #1771

gmpreussner opened this issue Dec 23, 2014 · 3 comments · Fixed by #22564

Comments

@gmpreussner
Copy link
Contributor

The following compiles and works as expected:

type
  Foo[X, T] = object
    bar: array[X, T]

However, this does not compile (fails to match X.low, X.high):

type
  Foo[X, T] = object
    bar: array[X.low..X.high, T]

Interestingly, this will compile and work though:

proc test[X, T](f: Foo[X, T]) =
  for i in X.low..X.high:
    echo f.bar[i]

But this doesn't compile (fails to match X.low):

proc test[X, T](f: Foo[X, T]) =
  echo f.bar[X.low]

All of the above instantiated with:

var a: Foo[range[0..2], float]
test(a)

I'm not 100% sure if I'm doing things wrong or have the wrong expectations wrt ranges, but this looks like a bug to me.

@Araq
Copy link
Member

Araq commented Oct 30, 2017

Still an issue. -.-

bung87 added a commit to bung87/Nim that referenced this issue Oct 26, 2022
@metagn
Copy link
Collaborator

metagn commented Aug 27, 2023

All compile in 2.0 (low/high were probably special cased for this way before though):

type
  Foo[X, T] = object
    bar: array[X.low..X.high, T]

proc test[X, T](f: Foo[X, T]) =
  echo f.bar[X.low]

var a: Foo[range[0..2], float]
test(a)

metagn added a commit to metagn/Nim that referenced this issue Aug 27, 2023
closes nim-lang#12582, closes nim-lang#19552, closes nim-lang#2465, closes nim-lang#4596, closes nim-lang#15246,
closes nim-lang#12683, closes nim-lang#7889, closes nim-lang#4547, closes nim-lang#12415, closes nim-lang#2002,
closes nim-lang#1771, closes nim-lang#5121

The test for nim-lang#5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.
@Araq Araq closed this as completed in c19fd69 Aug 27, 2023
@gmpreussner
Copy link
Contributor Author

Woohoo... time to check out 2.0 :)

narimiran pushed a commit that referenced this issue Sep 18, 2023
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test

(cherry picked from commit c19fd69)
narimiran pushed a commit that referenced this issue Sep 18, 2023
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test

(cherry picked from commit c19fd69)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants