mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
fixes #217
This commit is contained in:
@@ -1139,7 +1139,7 @@ proc semStmtList(c: PContext, n: PNode): PNode =
|
||||
# a statement list (s; e) has the type 'e':
|
||||
if result.kind == nkStmtList and result.len > 0:
|
||||
var lastStmt = lastSon(result)
|
||||
if not ImplicitelyDiscardable(lastStmt):
|
||||
if lastStmt.kind != nkNilLit and not ImplicitelyDiscardable(lastStmt):
|
||||
result.typ = lastStmt.typ
|
||||
#localError(lastStmt.info, errGenerated,
|
||||
# "Last expression must be explicitly returned if it " &
|
||||
|
||||
@@ -279,24 +279,24 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
var m = typeRel(c, f.sons[0], a.sons[0])
|
||||
# Subtype is sufficient for return types!
|
||||
if m < isSubtype or inconsistentVarTypes(f.sons[0], a.sons[0]):
|
||||
result = isNone
|
||||
return isNone
|
||||
elif m == isSubtype: result = isConvertible
|
||||
else: result = minRel(m, result)
|
||||
else:
|
||||
result = isNone
|
||||
return isNone
|
||||
elif a.sons[0] != nil:
|
||||
result = isNone
|
||||
return isNone
|
||||
if tfNoSideEffect in f.flags and tfNoSideEffect notin a.flags:
|
||||
result = isNone
|
||||
return isNone
|
||||
elif tfThread in f.flags and a.flags * {tfThread, tfNoSideEffect} == {}:
|
||||
# noSideEffect implies ``tfThread``! XXX really?
|
||||
result = isNone
|
||||
return isNone
|
||||
elif f.callconv != a.callconv:
|
||||
# valid to pass a 'nimcall' thingie to 'closure':
|
||||
if f.callconv == ccClosure and a.callconv == ccDefault:
|
||||
result = isConvertible
|
||||
else:
|
||||
result = isNone
|
||||
return isNone
|
||||
else: nil
|
||||
|
||||
proc matchTypeClass(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
|
||||
6
tests/compile/tprocvars.nim
Normal file
6
tests/compile/tprocvars.nim
Normal file
@@ -0,0 +1,6 @@
|
||||
proc doSomething(v: Int, x: proc(v:Int):Int): Int = return x(v)
|
||||
proc doSomething(v: Int, x: proc(v:Int)) = x(v)
|
||||
|
||||
|
||||
echo doSomething(10, proc(v: Int): Int = return v div 2)
|
||||
|
||||
Reference in New Issue
Block a user