diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-04-28 17:40:57 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2017-04-28 17:40:57 +0300 |
commit | c981284ddcbfe192b3554c9730b5fa6fc1b35a17 (patch) | |
tree | e99fa4816392dcc2f7320187982d623646802f98 /compiler | |
parent | bc01835091df93d8d278a55c62338e96be646e46 (diff) | |
download | Nim-c981284ddcbfe192b3554c9730b5fa6fc1b35a17.tar.gz |
a simple way to simulate covariance in generic types
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/sigmatch.nim | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index d6a0c6382..db3775cca 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -956,6 +956,8 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = case a.kind of tyOr: + # XXX: deal with the current dual meaning of tyGenericParam + c.typedescMatched = true # seq[int|string] vs seq[number] # both int and string must match against number # but ensure that '[T: A|A]' matches as good as '[T: A]' (bug #2219): @@ -964,15 +966,18 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = let x = typeRel(c, f, branch, false) if x == isNone: return isNone if x < result: result = x + return of tyAnd: + # XXX: deal with the current dual meaning of tyGenericParam + c.typedescMatched = true # seq[Sortable and Iterable] vs seq[Sortable] # only one match is enough for branch in a.sons: let x = typeRel(c, f, branch, false) if x != isNone: return if x >= isGeneric: isGeneric else: x - result = isNone + return isNone of tyNot: case f.kind |