-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Overload resolution broken with subclassing + or
#16321
Comments
Another test: type
Foo*[K] = object
item: K
template empty*[K](t: typedesc[K]): K = high(t)
proc initFoo*[K](): Foo[K] =
result = Foo[K](item: empty(K))
type
Bar = distinct uint16
proc `==`(a, b: Bar): bool {.borrow.}
template empty*(t: typedesc[Bar]): Bar = Bar(0)
var x = initFoo[Bar]()
assert x.item == Bar(0) |
always try to minimize please ;-) Here's a minimized repro without imports, and here's an updated diagnostic: overload resolution wrongly favors when true:
type Stream = object of RootObj
type Stream2 = object of Stream
type Foo[T] = object
proc storeBin[T](s: Stream; o: Foo[T]) = discard
proc storeBin[T: float|object](s: Stream; o: T) = doAssert false
# var s = Stream() # ok
var s = Stream2() # bug
s.storeBin(Foo[int]()) linkssigmatch.ninm: see isSubtype, subtypeMatches, isGeneric |
Thanks! I tried my best but you helped to make it even smaller. |
or
I don't know if you want me to submit different issues, but second test case is not related to subclassing as far as I can tell :) |
ya, it may be a different bug then. Maybe try to take a stab at a PR? See sigmatch.nim, it sounds not too complicated (YMMV) |
sure will try tomorrow |
In the code below, overload for Option is not used instead the generic object overload takes its place.
Example
Current Output
Expected Output
Additional Information
object|tuple
type class, into separate procs, fixes it.var
parameter instoreBin
proc, fixes it.storeBin
into another generic proc, fixes it.The text was updated successfully, but these errors were encountered: