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

Compiler cannot distinguish ==(x: T: MyTypes, y: T: MyTypes) from system.==(x: T: tuple or object, y: T: tuple or object) #16870

Open
rockcavera opened this issue Jan 30, 2021 · 0 comments

Comments

@rockcavera
Copy link
Contributor

The compiler is unable to choose a proc with a generic type over the "more generic" type object. By changing some things in the comparison procs it is possible to compile. However, the compiler is expected to be smart enough to distinguish types.

Example

# comp.nim
type
  TypeOne* = object
    a*: int
  TypeTwo* = object
    a*: uint
  
  MyTypes* = TypeOne|TypeTwo

proc `==`*[T: MyTypes](x, y: T): bool =
  x.a == y.a
# bug.nim
import ./comp

var
  x = TypeOne(a: 0)
  y = TypeOne(a: 0)

echo x == y

Compile: nim c bug.nim

Current Output

c:\Users\Jose\Desktop\bugequal>nim c bug
Hint: used config file 'D:\nim\config\nim.cfg' [Conf]
Hint: used config file 'D:\nim\config\config.nims' [Conf]
.....
c:\Users\Jose\Desktop\bugequal\bug.nim(7, 8) Error: ambiguous call; both system.==(x: T: tuple or object, y: T: tuple or object) [proc declared in D:\nim\lib\system.nim(1846, 6)] and comp.==(x: T: MyTypes, y: T: MyTypes) [proc declared in c:\Users\Jose\Desktop\bugequal\comp.nim(9, 6)] match for: (TypeOne, TypeOne)

Expected Output

That compiles correctly

Possible Solution

  • Make the compiler distinguish a generic type from the "more generic" type object

Additional Information

Nim Compiler Version 1.5.1 [Windows: amd64]
Compiled at 2021-01-30
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: b8e8eaae66c3298d25a324e939ca6c1fd69a9652
active boot switches: -d:release
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

2 participants