diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index ac375e7933..33ab827d3b 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -204,7 +204,6 @@ proc semSizeof(c: PContext, n: PNode): PNode = proc semOf(c: PContext, n: PNode): PNode = if sonsLen(n) == 3: - #LocalError(n.info, errXcanNeverBeOfThisSubtype, " CAME HERE") n.sons[1] = semExprWithType(c, n.sons[1], {efAllowType}) n.sons[2] = semExprWithType(c, n.sons[2], {efAllowType}) var a = skipTypes(n.sons[1].typ, abstractPtrs) @@ -220,22 +219,14 @@ proc semOf(c: PContext, n: PNode): PNode = result = n proc semIs(c: PContext, n: PNode): PNode = - GlobalError(n.info, errXExpectsTwoArguments, "is") - if sonsLen(n) == 3: - #LocalError(n.info, errXcanNeverBeOfThisSubtype, " CAME HERE") - n.sons[1] = semExprWithType(c, n.sons[1], {efAllowType}) - n.sons[2] = semExprWithType(c, n.sons[2], {efAllowType}) - var a = skipTypes(n.sons[1].typ, abstractPtrs) - var b = skipTypes(n.sons[2].typ, abstractPtrs) - if b.kind != tyObject or a.kind != tyObject: - GlobalError(n.info, errXExpectsObjectTypes, "is") - while b != nil and b.id != a.id: b = b.sons[0] - if b == nil: - GlobalError(n.info, errXcanNeverBeOfThisSubtype, typeToString(a)) - n.typ = getSysType(tyBool) - else: + if sonsLen(n) == 3: + var a = semExprWithType(c, n.sons[1], {efAllowType}) + var b = semExprWithType(c, n.sons[2], {efAllowType}) + result = newIntNode(nkIntLit, ord(sameType(a.typ, b.typ))) + result.typ = getSysType(tyBool) + result.info = n.info + else: GlobalError(n.info, errXExpectsTwoArguments, "is") - result = n proc semOpAux(c: PContext, n: PNode) = for i in countup(1, sonsLen(n) - 1): diff --git a/compiler/semfold.nim b/compiler/semfold.nim index dbd5d34e5b..028143ae99 100755 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -348,14 +348,14 @@ proc getConstExpr(m: PSym, n: PNode): PNode = of nkIfExpr: result = getConstIfExpr(m, n) of nkCall, nkCommand, nkCallStrLit: - if (n.sons[0].kind != nkSym): return + if n.sons[0].kind != nkSym: return var s = n.sons[0].sym - if (s.kind != skProc): return - try: + if s.kind != skProc: return + try: case s.magic - of mNone: + of mNone: return # XXX: if it has no sideEffect, it should be evaluated - of mSizeOf: + of mSizeOf: var a = n.sons[1] if computeSize(a.typ) < 0: LocalError(a.info, errCannotEvalXBecauseIncompletelyDefined, diff --git a/tests/accept/run/tisopr.nim b/tests/accept/run/tisopr.nim new file mode 100644 index 0000000000..6d3c51749b --- /dev/null +++ b/tests/accept/run/tisopr.nim @@ -0,0 +1,13 @@ +discard """ + output: "true true false yes" +""" + +proc IsVoid[T](): string = + when T is void: + result = "yes" + else: + result = "no" + +const x = int is int +echo x, " ", float is float, " ", float is string, " ", IsVoid[void]() + diff --git a/todo.txt b/todo.txt index 6fbd4e68cc..23ecc52c54 100755 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,6 @@ Version 0.8.14 ============== -- ``when T is int`` for generic code - ``var T`` as a return type: * for iterators * add ``modGet`` for generics