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

Overloading resolution - Specializing generic proc like $ #5645

Closed
mratsim opened this issue Apr 1, 2017 · 2 comments
Closed

Overloading resolution - Specializing generic proc like $ #5645

mratsim opened this issue Apr 1, 2017 · 2 comments
Assignees

Comments

@mratsim
Copy link
Collaborator

mratsim commented Apr 1, 2017

Related to #5644, #1991 and commit f8c921d.

Overloading resolution works as expected when the proc definition and the proc call are in the same file.
However there are conflicts when proc is called from another module.
It might be as "intended" from the manual

Rule #3: Generic match: f is a generic type and a matches, for instance a is int and f is a generic (constrained) parameter type (like in [T] or [T: int|char].

but this prevents specializing proc like $ for typeclass and maybe concepts:

Test case in 2 files

# Filename: test1.nim

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

proc zeros*(M,N: static[int], T: typedesc[float64]): Matrix[M,N,T] =
  new result.data
  for i in 0 .. < (M * N):
    result.data[i] = 0

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

File2

import test1

proc baz*[T](a: T) =
  echo a

let a = zeros(2,2, float64)

baz(a)

Error

ambiguous call; both system.$(x: T) and test1.$(m: Matrix32[$.M, $.N] or Matrix64[$.M, $.N]) match for: (Matrix[2, 2, system.float64])
@Clyybber
Copy link
Contributor

Works on devel. (replace SomeReal with SomeFloat in the testcase)

@krux02 krux02 closed this as completed Jan 10, 2019
@Araq
Copy link
Member

Araq commented Jan 10, 2019

This needs a test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants