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 - type subset of generic type - clang compiler error on multiple arguments #5643

Closed
mratsim opened this issue Apr 1, 2017 · 0 comments
Assignees

Comments

@mratsim
Copy link
Collaborator

mratsim commented Apr 1, 2017

I'm refactoring https://github.com/unicredit/linear-algebra/ and creating a generic Matrix[M, N, T] of which Matrix32[M, N] and Matrix64[M, N] will be subset to maintain backward compatibility.

I got a strange error on clang with the following test case

type
  Matrix*[M, N: static[int], T: SomeReal] = object
    data: ref array[N * M, T]
  Matrix64*[M, N: static[int]] = Matrix[M, N, float64]

proc zeros64(M,N: static[int]): Matrix64[M,N] =
  new result.data
  for i in 0 .. < (M * N):
    result.data[i] = 0'f64

proc `$`*[M, N: static[int]](m: Matrix64[M, N]): string =
  result = "64"

proc foo*[M,N: static[int], T](a: Matrix[M,N,T]) =
  echo a

proc bar*[M,N: static[int], T](a: Matrix[M,N,T], b: Matrix[M,N,T]) =
  echo a


let a = zeros64(2,2)
foo(a) #works
bar(a,a) #fails

Error is

Hint: used config file '/usr/local/Cellar/nim/HEAD-7e351fc/nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: playground2 [Processing]
CC: linalg_playground2
Error: execution of an external compiler program 'clang -c  -w  -I/usr/local/Cellar/nim/HEAD-7e351fc/nim/lib -o nimcache/linalg_playground2.o nimcache/linalg_playground2.c' failed with exit code: 1

nimcache/linalg_playground2.c:260:57: error: passing 'Matrix_Nb9aIVumBEh1lQnIqrfOM9ag' (aka 'struct Matrix_Nb9aIVumBEh1lQnIqrfOM9ag') to parameter of incompatible type 'Matrix_t9aff0BJYnei5m71SWTA5Wg' (aka 'struct Matrix_t9aff0BJYnei5m71SWTA5Wg')
        bar_dxw2HPX6uLOVcW9bsla0gNA(a_UlQDd4uj9bxnRSukXNrxCBQ, a_UlQDd4uj9bxnRSukXNrxCBQ);
                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~
nimcache/linalg_playground2.c:200:112: note: passing argument to parameter 'b' here
N_NIMCALL(void, bar_dxw2HPX6uLOVcW9bsla0gNA)(Matrix_Nb9aIVumBEh1lQnIqrfOM9ag a, Matrix_t9aff0BJYnei5m71SWTA5Wg b) {
                                                                                                               ^
1 error generated.
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

2 participants