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

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

Closed
ishowta opened this issue Dec 28, 2017 · 3 comments · Fixed by #20931
Closed

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

ishowta opened this issue Dec 28, 2017 · 3 comments · Fixed by #20931
Labels

Comments

@ishowta
Copy link
Contributor

ishowta commented Dec 28, 2017

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)
@ghost
Copy link

ghost commented Dec 28, 2017

@kinironote do you think this code should work or not?

@ghost ghost added the Generics label Dec 28, 2017
@ishowta
Copy link
Contributor Author

ishowta commented Dec 28, 2017

I think this code should work.
As far as I've tried, it seems that an error occurs regardless of what operator () is declared.

{.experimental.}

var s = newSeq[int](3)

echo s  # ok
{.experimental.}

proc `()`(a:string, b:string):string = a & b

var s = newSeq[int](3)

echo s  # error

I may be misunderstanding something. I'm sorry.

@shirleyquirk
Copy link
Contributor

Reduced:

{.experimental: "callOperator".}

type Foo = object
proc `()`(foo: Foo) = discard

proc mewSeq[T](a,b:int)=discard
proc mewSeq[T](c:int)= discard
mewSeq[int]()

Obviously the above shouldn't compile, but mewSeq[int](5) also doesn't compile and the error message is the point:

/usercode/in.nim(8, 12) Error: type mismatch: got <proc (a: int, b: int){.noSideEffect, gcsafe, locks: 0.} | proc (c: int){.noSideEffect, gcsafe, locks: 0.}>
but expected one of: 
proc `()`(foo: Foo)
  first type mismatch at position: 1
  required type for foo: Foo
  but expression 'mewSeq' is of type: void

expression: ()(mewSeq)

metagn added a commit to metagn/Nim that referenced this issue Nov 26, 2022
@Araq Araq closed this as completed in 555c5ed Nov 28, 2022
narimiran pushed a commit that referenced this issue Nov 30, 2022
* better error messages for dot operators [backport]

fixes #13063

* also fixes #7777

* fix #6981 and #9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements

(cherry picked from commit 555c5ed)
survivorm pushed a commit to survivorm/Nim that referenced this issue Feb 28, 2023
* better error messages for dot operators [backport]

fixes nim-lang#13063

* also fixes nim-lang#7777

* fix nim-lang#6981 and nim-lang#9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
* better error messages for dot operators [backport]

fixes nim-lang#13063

* also fixes nim-lang#7777

* fix nim-lang#6981 and nim-lang#9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
* better error messages for dot operators [backport]

fixes nim-lang#13063

* also fixes nim-lang#7777

* fix nim-lang#6981 and nim-lang#9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants