Skip to content

An error occurs when calling generic and overloaded proc with declare operator () #6981

Closed
@ishowta

Description

@ishowta
Nim Compiler Version 0.17.3 [Linux: amd64]
Copyright (c) 2006-2017 by Andreas Rumpf

git hash: 7e6dc3679aaf463a957af7ff6bb34317c7656d4c
active boot switches: -d:release
{.experimental: "callOperator".}

proc noGenericProc(n:int)                    = discard

proc noGenericWithOverloadingProc(n:int)     = discard
proc noGenericWithOverloadingProc(n:string)  = discard

proc genericProc[T](n:int)                   = discard

proc genericWithOverloadingProc[T](n:int)    = discard
proc genericWithOverloadingProc[T](n:string) = discard

block:
  noGenericProc(1)                    # ok
  noGenericWithOverloadingProc(1)     # ok
  genericProc[int](1)                 # ok
  genericWithOverloadingProc[int](1)  # ok

block:
  type A = object
  type B = object
  proc `()`(a:A, b:B) = discard

  noGenericProc(1)                    # ok
  noGenericWithOverloadingProc(1)     # ok
  genericProc[int](1)                 # ok
  genericWithOverloadingProc[int](1)  # error

  discard newSeq[int](1)              # this also error
test.nim(29, 34) Error: type mismatch: got (proc (n: int){.noSideEffect, gcsafe, locks: 0.} | proc (n: string){.noSideEffect, gcsafe, locks: 0.}, int literal(1))
but expected one of:
proc `()`(a: A; b: B)

expression: ()(genericWithOverloadingProc, 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions