Skip to content

Commit 1de4eff

Browse files
committed
Merge branch 'master' of github.com:Araq/Nimrod
2 parents 7c08d14 + 27dc9fc commit 1de4eff

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

compiler/ccgcalls.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
121121
var op: TLoc
122122
# this is a hotspot in the compiler
123123
initLocExpr(p, ri.sons[0], op)
124-
var pl = con(op.r, "(")
124+
var params: PRope
125125
# getUniqueType() is too expensive here:
126126
var typ = skipTypes(ri.sons[0].typ, abstractInst)
127127
assert(typ.kind == tyProc)
128128
var length = sonsLen(ri)
129129
for i in countup(1, length - 1):
130130
assert(sonsLen(typ) == sonsLen(typ.n))
131131
if ri.sons[i].typ.isCompileTimeOnly: continue
132+
if params != nil: app(params, ", ")
132133
if i < sonsLen(typ):
133134
assert(typ.n.sons[i].kind == nkSym)
134-
app(pl, genArg(p, ri.sons[i], typ.n.sons[i].sym))
135+
app(params, genArg(p, ri.sons[i], typ.n.sons[i].sym))
135136
else:
136-
app(pl, genArgNoParam(p, ri.sons[i]))
137-
if i < length - 1: app(pl, ", ")
138-
fixupCall(p, le, ri, d, pl)
137+
app(params, genArgNoParam(p, ri.sons[i]))
138+
fixupCall(p, le, ri, d, con(op.r, "(".toRope, params))
139139

140140
proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
141141

compiler/ccgtypes.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var PRope,
290290
if t.n.sons[i].kind != nkSym: InternalError(t.n.info, "genProcParams")
291291
var param = t.n.sons[i].sym
292292
if isCompileTimeOnly(param.typ): continue
293+
if params != nil: app(params, ", ")
293294
fillLoc(param.loc, locParam, param.typ, mangleName(param), OnStack)
294295
app(params, getParamTypeDesc(m, param.typ, check))
295296
if ccgIntroducedPtr(param):
@@ -309,7 +310,6 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var PRope,
309310
appff(params, ", NI $1Len$2", ", @NI $1Len$2", [param.loc.r, j.toRope])
310311
inc(j)
311312
arr = arr.sons[0]
312-
if i < sonsLen(t.n) - 1: app(params, ", ")
313313
if (t.sons[0] != nil) and isInvalidReturnType(t.sons[0]):
314314
var arr = t.sons[0]
315315
if params != nil: app(params, ", ")

compiler/sigmatch.nim

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,31 +257,31 @@ proc tupleRel(c: var TCandidate, f, a: PType): TTypeRelation =
257257
var y = a.n.sons[i].sym
258258
if x.name.id != y.name.id: return isNone
259259

260-
proc matchTypeClass(c: var TCandidate, f, a: PType): TTypeRelation =
261-
for i in countup(0, f.sonsLen - 1):
262-
let son = f.sons[i]
263-
var match = son.kind == skipTypes(a, {tyRange, tyGenericInst}).kind
264-
260+
proc matchTypeClass(c: var TCandidate, typeClass, t: PType): TTypeRelation =
261+
for i in countup(0, typeClass.sonsLen - 1):
262+
let req = typeClass.sons[i]
263+
var match = req.kind == skipTypes(t, {tyRange, tyGenericInst}).kind
264+
265265
if not match:
266-
case son.kind
266+
case req.kind
267267
of tyGenericBody:
268-
if a.kind == tyGenericInst and a.sons[0] == son:
268+
if t.kind == tyGenericInst and t.sons[0] == req:
269269
match = true
270-
put(c.bindings, f, a)
270+
put(c.bindings, typeClass, t)
271271
of tyTypeClass:
272-
match = matchTypeClass(c, son, a) == isGeneric
272+
match = matchTypeClass(c, req, t) == isGeneric
273273
else: nil
274+
elif t.kind in {tyTypeDesc, tyObject}:
275+
match = sameType(t, req)
274276

275-
if tfAny in f.flags:
276-
if match:
277-
return isGeneric
277+
if tfAny in typeClass.flags:
278+
if match: return isGeneric
278279
else:
279-
if not match:
280-
return isNone
280+
if not match: return isNone
281281

282282
# if the loop finished without returning, either all constraints matched
283283
# or none of them matched.
284-
result = if tfAny in f.flags: isNone else: isGeneric
284+
result = if tfAny in typeClass.flags: isNone else: isGeneric
285285

286286
proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
287287
proc inconsistentVarTypes(f, a: PType): bool {.inline.} =

compiler/types.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
431431
add(result, typeToString(t.sons[i]))
432432
add(result, ']')
433433
of tyTypeDesc:
434-
if t.sons.len == 0: result = "typedesc"
434+
if t.sons == nil or t.sons.len == 0: result = "typedesc"
435435
else: result = "typedesc[" & constraintsToStr(t) & "]"
436436
of tyTypeClass:
437437
result = constraintsToStr(t)

tests/run/ttypedesc1.nim

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ proc foo(T: typedesc[int or bool]): string =
1919
template foo(T: typedesc[seq]): expr = "seq"
2020

2121
test "types can be used as proc params":
22-
check foo(TFoo[int, float], 1000) == "TFoo 1000"
22+
# XXX: `check` needs to know that TFoo[int, float] is a type and
23+
# cannot be assigned for a local variable for later inspection
24+
check ((foo(TFoo[int, float], 1000) == "TFoo 1000"))
2325

2426
var f = 10.0
25-
check foo(float, "long string") == "float true"
26-
check foo(type(f), [1, 2, 3]) == "float false"
27+
check ((foo(float, "long string") == "float true"))
28+
check ((foo(type(f), [1, 2, 3]) == "float false"))
2729

28-
check foo(int) == "int or bool 10"
30+
check ((foo(int) == "int or bool 10"))
2931

30-
check foo(seq[int]) == "seq"
31-
check foo(seq[TFoo[bool, string]]) == "seq"
32+
check ((foo(seq[int]) == "seq"))
33+
check ((foo(seq[TFoo[bool, string]]) == "seq"))
3234

3335
when false:
3436
proc foo(T: typedesc[seq], s: T) = nil

0 commit comments

Comments
 (0)