This commit is contained in:
parent
c52a2c3ab0
commit
e58c2d261c
3 changed files with 32 additions and 7 deletions
|
|
@ -134,11 +134,14 @@ proc initCandidate*(ctx: PContext, c: var TCandidate, callee: PType) =
|
||||||
initIdTable(c.bindings)
|
initIdTable(c.bindings)
|
||||||
|
|
||||||
proc put(c: var TCandidate, key, val: PType) {.inline.} =
|
proc put(c: var TCandidate, key, val: PType) {.inline.} =
|
||||||
|
## Given: proc foo[T](x: T); foo(4)
|
||||||
|
## key: 'T'
|
||||||
|
## val: 'int' (typeof(4))
|
||||||
when false:
|
when false:
|
||||||
let old = PType(idTableGet(c.bindings, key))
|
let old = PType(idTableGet(c.bindings, key))
|
||||||
if old != nil:
|
if old != nil:
|
||||||
echo "Putting ", typeToString(key), " ", typeToString(val), " and old is ", typeToString(old)
|
echo "Putting ", typeToString(key), " ", typeToString(val), " and old is ", typeToString(old)
|
||||||
if typeToString(old) == "seq[string]":
|
if typeToString(old) == "float32":
|
||||||
writeStackTrace()
|
writeStackTrace()
|
||||||
if c.c.module.name.s == "temp3":
|
if c.c.module.name.s == "temp3":
|
||||||
echo "binding ", key, " -> ", val
|
echo "binding ", key, " -> ", val
|
||||||
|
|
@ -2551,13 +2554,18 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||||
formal.name.s)
|
formal.name.s)
|
||||||
if nfDefaultRefsParam in formal.ast.flags:
|
if nfDefaultRefsParam in formal.ast.flags:
|
||||||
m.call.flags.incl nfDefaultRefsParam
|
m.call.flags.incl nfDefaultRefsParam
|
||||||
var def = copyTree(formal.ast)
|
var defaultValue = copyTree(formal.ast)
|
||||||
if def.kind == nkNilLit:
|
if defaultValue.kind == nkNilLit:
|
||||||
def = implicitConv(nkHiddenStdConv, formal.typ, def, m, c)
|
defaultValue = implicitConv(nkHiddenStdConv, formal.typ, defaultValue, m, c)
|
||||||
|
# proc foo(x: T = 0.0)
|
||||||
|
# foo()
|
||||||
if {tfImplicitTypeParam, tfGenericTypeParam} * formal.typ.flags != {}:
|
if {tfImplicitTypeParam, tfGenericTypeParam} * formal.typ.flags != {}:
|
||||||
put(m, formal.typ, def.typ)
|
let existing = PType(idTableGet(m.bindings, formal.typ))
|
||||||
def.flags.incl nfDefaultParam
|
if existing == nil or existing.kind == tyTypeDesc:
|
||||||
setSon(m.call, formal.position + 1, def)
|
# see bug #11600:
|
||||||
|
put(m, formal.typ, defaultValue.typ)
|
||||||
|
defaultValue.flags.incl nfDefaultParam
|
||||||
|
setSon(m.call, formal.position + 1, defaultValue)
|
||||||
inc(f)
|
inc(f)
|
||||||
# forget all inferred types if the overload matching failed
|
# forget all inferred types if the overload matching failed
|
||||||
if m.state == csNoMatch:
|
if m.state == csNoMatch:
|
||||||
|
|
|
||||||
|
|
@ -451,3 +451,6 @@ when isMainModule:
|
||||||
doAssert(sizeof(a) == 16)
|
doAssert(sizeof(a) == 16)
|
||||||
|
|
||||||
doAssert 123.0.im + 456.0 == complex64(456, 123)
|
doAssert 123.0.im + 456.0 == complex64(456, 123)
|
||||||
|
|
||||||
|
var localA = complex(0.1'f32)
|
||||||
|
doAssert localA.im is float32
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ discard """
|
||||||
output: '''
|
output: '''
|
||||||
100
|
100
|
||||||
0
|
0
|
||||||
|
float32
|
||||||
|
float32
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -110,3 +112,15 @@ block tgeneric4:
|
||||||
newSeq result.free, 0
|
newSeq result.free, 0
|
||||||
|
|
||||||
var x = newIDGen[int]()
|
var x = newIDGen[int]()
|
||||||
|
|
||||||
|
block tgeneric5:
|
||||||
|
# bug #12528
|
||||||
|
proc foo[T](a: T; b: T) =
|
||||||
|
echo T
|
||||||
|
|
||||||
|
foo(0.0'f32, 0.0)
|
||||||
|
|
||||||
|
proc bar[T](a: T; b: T = 0.0) =
|
||||||
|
echo T
|
||||||
|
|
||||||
|
bar(0.0'f32)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue