fixes #7854
This commit is contained in:
parent
8e33667262
commit
e98e214422
2 changed files with 38 additions and 1 deletions
|
|
@ -1921,6 +1921,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
|
||||||
result.typ.n = arg
|
result.typ.n = arg
|
||||||
return
|
return
|
||||||
|
|
||||||
|
let oldInheritancePenalty = m.inheritancePenalty
|
||||||
var r = typeRel(m, f, a)
|
var r = typeRel(m, f, a)
|
||||||
|
|
||||||
# This special typing rule for macros and templates is not documented
|
# 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:
|
if arg.typ == nil:
|
||||||
result = arg
|
result = arg
|
||||||
elif skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple or
|
elif skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple or
|
||||||
m.inheritancePenalty > 0:
|
m.inheritancePenalty > oldInheritancePenalty:
|
||||||
result = implicitConv(nkHiddenSubConv, f, arg, m, c)
|
result = implicitConv(nkHiddenSubConv, f, arg, m, c)
|
||||||
elif arg.typ.isEmptyContainer:
|
elif arg.typ.isEmptyContainer:
|
||||||
result = arg.copyTree
|
result = arg.copyTree
|
||||||
|
|
|
||||||
36
tests/generics/tgenerics_and_inheritance.nim
Normal file
36
tests/generics/tgenerics_and_inheritance.nim
Normal file
|
|
@ -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)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue