diff options
author | Araq <rumpf_a@web.de> | 2018-08-29 15:46:50 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-08-30 15:49:51 +0200 |
commit | e98e21442253c8f376e2b48753ed036dbd99aa9f (patch) | |
tree | ea74024e531c3e77378d5b63471dc3cee09438b5 | |
parent | 8e336672623c1b36baf2b89117cc62516ac61c30 (diff) | |
download | Nim-e98e21442253c8f376e2b48753ed036dbd99aa9f.tar.gz |
fixes #7854
-rw-r--r-- | compiler/sigmatch.nim | 3 | ||||
-rw-r--r-- | tests/generics/tgenerics_and_inheritance.nim | 36 |
2 files changed, 38 insertions, 1 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 932163055..c53c73074 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1921,6 +1921,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, result.typ.n = arg return + let oldInheritancePenalty = m.inheritancePenalty var r = typeRel(m, f, a) # This special typing rule for macros and templates is not documented @@ -2002,7 +2003,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, if arg.typ == nil: result = arg elif skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple or - m.inheritancePenalty > 0: + m.inheritancePenalty > oldInheritancePenalty: result = implicitConv(nkHiddenSubConv, f, arg, m, c) elif arg.typ.isEmptyContainer: result = arg.copyTree diff --git a/tests/generics/tgenerics_and_inheritance.nim b/tests/generics/tgenerics_and_inheritance.nim new file mode 100644 index 000000000..ea776b517 --- /dev/null +++ b/tests/generics/tgenerics_and_inheritance.nim @@ -0,0 +1,36 @@ + +# bug #7854 + +type + Stream* = ref StreamObj + StreamObj* = object of RootObj + + InhStream* = ref InhStreamObj + InhStreamObj* = object of Stream + f: string + +proc newInhStream*(f: string): InhStream = + new(result) + result.f = f + +var val: int +let str = newInhStream("input_file.json") + +block: + # works: + proc load[T](data: var T, s: Stream) = + discard + load(val, str) + +block: + # works + proc load[T](s: Stream, data: T) = + discard + load(str, val) + +block: + # broken + proc load[T](s: Stream, data: var T) = + discard + load(str, val) + |