mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
This commit is contained in:
@@ -134,11 +134,14 @@ proc initCandidate*(ctx: PContext, c: var TCandidate, callee: PType) =
|
||||
initIdTable(c.bindings)
|
||||
|
||||
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:
|
||||
let old = PType(idTableGet(c.bindings, key))
|
||||
if old != nil:
|
||||
echo "Putting ", typeToString(key), " ", typeToString(val), " and old is ", typeToString(old)
|
||||
if typeToString(old) == "seq[string]":
|
||||
if typeToString(old) == "float32":
|
||||
writeStackTrace()
|
||||
if c.c.module.name.s == "temp3":
|
||||
echo "binding ", key, " -> ", val
|
||||
@@ -2551,13 +2554,18 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||
formal.name.s)
|
||||
if nfDefaultRefsParam in formal.ast.flags:
|
||||
m.call.flags.incl nfDefaultRefsParam
|
||||
var def = copyTree(formal.ast)
|
||||
if def.kind == nkNilLit:
|
||||
def = implicitConv(nkHiddenStdConv, formal.typ, def, m, c)
|
||||
var defaultValue = copyTree(formal.ast)
|
||||
if defaultValue.kind == nkNilLit:
|
||||
defaultValue = implicitConv(nkHiddenStdConv, formal.typ, defaultValue, m, c)
|
||||
# proc foo(x: T = 0.0)
|
||||
# foo()
|
||||
if {tfImplicitTypeParam, tfGenericTypeParam} * formal.typ.flags != {}:
|
||||
put(m, formal.typ, def.typ)
|
||||
def.flags.incl nfDefaultParam
|
||||
setSon(m.call, formal.position + 1, def)
|
||||
let existing = PType(idTableGet(m.bindings, formal.typ))
|
||||
if existing == nil or existing.kind == tyTypeDesc:
|
||||
# see bug #11600:
|
||||
put(m, formal.typ, defaultValue.typ)
|
||||
defaultValue.flags.incl nfDefaultParam
|
||||
setSon(m.call, formal.position + 1, defaultValue)
|
||||
inc(f)
|
||||
# forget all inferred types if the overload matching failed
|
||||
if m.state == csNoMatch:
|
||||
|
||||
@@ -451,3 +451,6 @@ when isMainModule:
|
||||
doAssert(sizeof(a) == 16)
|
||||
|
||||
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: '''
|
||||
100
|
||||
0
|
||||
float32
|
||||
float32
|
||||
'''
|
||||
"""
|
||||
|
||||
@@ -110,3 +112,15 @@ block tgeneric4:
|
||||
newSeq result.free, 0
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user