-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
typeRel
behave to spec (#22261)
The goal of this PR is to make `typeRel` accurate to it's definition for generics: ``` # 3) When used with two type classes, it will check whether the types # matching the first type class (aOrig) are a strict subset of the types matching # the other (f). This allows us to compare the signatures of generic procs in # order to give preferrence to the most specific one: ``` I don't want this PR to break any code, and I want to preserve all of Nims current behaviors. I think that making this more accurate will help serve as ground work for the future. It may not be possible to not break anything but this is my attempt. So that it is understood, this code was part of another PR (#22143) but that problem statement only needed this change by extension. It's more organized to split two problems into two PRs and this issue, being non-breaking, should be a more immediate improvement. --------- Co-authored-by: Andreas Rumpf <[email protected]> (cherry picked from commit b2ca6be)
- Loading branch information
Showing
4 changed files
with
78 additions
and
29 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
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
discard """ | ||
errormsg: "ambiguous call;" | ||
line: 16 | ||
""" | ||
|
||
# bug #8568 | ||
|
||
type | ||
D[T] = object | ||
E[T] = object | ||
|
||
proc g(a: D|E): string = "foo D|E" | ||
proc g(a: D): string = "foo D" | ||
block: # PR #22261 | ||
proc d(x: D):bool= false | ||
proc d(x: int | D[SomeInteger]):bool= true | ||
doAssert d(D[5]()) == false | ||
|
||
proc test() = | ||
let x = g D[int]() | ||
|
||
test() | ||
block: # bug #8568 | ||
#[ | ||
Since PR #22261 and amendment has been made. Since D is a subset of D | E but | ||
not the other way around `checkGeneric` should favor proc g(a: D) instead | ||
of asserting ambiguity | ||
]# | ||
proc g(a: D|E): string = "foo D|E" | ||
proc g(a: D): string = "foo D" | ||
doAssert g(D[int]()) == "foo D" |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import std/[times, strformat] | ||
import std/assertions | ||
|
||
doAssert fmt"{getTime()}" == $getTime() | ||
doAssert fmt"{now()}" == $now() | ||
let aTime = getTime() | ||
doAssert fmt"{aTime}" == $aTime | ||
let aNow = now() | ||
doAssert fmt"{aNow}" == $aNow |