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

fun[T:openArray](a:T) != fun[T](a:openArray[T]) #9032

Closed
timotheecour opened this issue Sep 22, 2018 · 4 comments
Closed

fun[T:openArray](a:T) != fun[T](a:openArray[T]) #9032

timotheecour opened this issue Sep 22, 2018 · 4 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Sep 22, 2018

/cc @zah
Why is fun[T:openArray](a:T) not the same as fun[T](a:openArray[T]) ?

proc foo1[T:openArray](a:T):auto = low(a)
proc foo2[T](a:openArray[T]):auto = low(a)

proc test()=
  var a: array[3..6, int]
  echo (foo1(a), foo2(a)) # prints (Field0: 3, Field1: 0)

test()

I was looking at #9002 and was wondering how it worked with openArrays with different low values (eg array[3..6, int] and array[2..5, int]); it somehow works "thanks" to the fact that fun[T:openArray](a:T) != fun[T](a:openArray[T]) , but is this desired behavior?

@Clyybber
Copy link
Contributor

They are not the same. The meaning of T in foo1 is different from its meaning in foo2.
In foo1 it is the type of a, but in foo2 it is the type of the fields of a.
The fact that it prints different things is wierd though, and most likely a bug.

@metagn
Copy link
Collaborator

metagn commented Sep 22, 2018

I think it's to allow this:

proc foo[T](s: openarray[T]) =
  echo s[0]

let a: array[3..6, int] = [10, 11, 12]
let s = @[10, 11, 12] 
foo(a)
foo(s)

The manual states that openarray parameters always start with 0. The difference with T: openarray is that the openarray typeclass/concept is used instead of the openarray parameter type.

@krux02
Copy link
Contributor

krux02 commented Nov 1, 2018

I am closing this, because I collect issues like this in my own issue here: #9592

@krux02 krux02 closed this as completed Nov 1, 2018
@timotheecour timotheecour changed the title fun[T:openArray](a:T) != fun[T](a:openArray[T]) [superseded] fun[T:openArray](a:T) != fun[T](a:openArray[T]) Nov 1, 2018
@timotheecour
Copy link
Member Author

I collect issues like this in my own issue here

fine, but the title you picked doesn't reflect that issue

@timotheecour timotheecour changed the title [superseded] fun[T:openArray](a:T) != fun[T](a:openArray[T]) fun[T:openArray](a:T) != fun[T](a:openArray[T]) Nov 1, 2018
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

4 participants