forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed generic inheritances dispatch (nim-lang#5)
Using inherited generics does not dispatch properly and just takes the generic's base. This properly dispatches on the generic types so procs can overide based of inherited parameters. Making the following work: ```nim type A[T] {.inheritable.} = object B = object of A[int] C = object of A[float] proc doStuff(a: A[int]) = discard proc doStuff(a: A[float) = discard doStuff(B()) doStuff(C()) ```
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
discard """ | ||
action: reject | ||
cmd: '''nim check --hints:off $options $file''' | ||
nimoutFull: true | ||
nimout: ''' | ||
tinheritance_generic_dispatch.nim(43, 5) Error: type mismatch: got <U> | ||
but expected one of: | ||
proc test(u: Union[string, RootObj]) | ||
first type mismatch at position: 1 | ||
required type for u: Union[system.string, system.RootObj] | ||
but expression 'U()' is of type: U | ||
expression: test(U()) | ||
tinheritance_generic_dispatch.nim(45, 6) Error: type mismatch: got <T> | ||
but expected one of: | ||
proc test2(u: Union[int, float]) | ||
first type mismatch at position: 1 | ||
required type for u: Union[system.int, system.float] | ||
but expression 'T()' is of type: T | ||
expression: test2(T()) | ||
tinheritance_generic_dispatch.nim(47, 6) Error: type mismatch: got <Union[system.string, system.RootObj]> | ||
but expected one of: | ||
proc test2(u: Union[int, float]) | ||
first type mismatch at position: 1 | ||
required type for u: Union[system.int, system.float] | ||
but expression 'Union[string, RootObj]()' is of type: Union[system.string, system.RootObj] | ||
expression: test2(Union[string, RootObj]()) | ||
''' | ||
""" | ||
|
||
type | ||
Union[T, U] = object of RootObj | ||
|
||
U = object of Union[int, float] | ||
T = object of Union[string, RootObj] | ||
|
||
proc test(u: Union[string, RootObj]) = discard | ||
proc test2(u: Union[int, float]) = discard | ||
|
||
test(T()) | ||
test(U()) | ||
test(Union[string, RootObj]()) | ||
test2(T()) | ||
test2(U()) | ||
test2(Union[string, RootObj]()) |