diff options
Diffstat (limited to 'compiler/semexprs.nim')
-rw-r--r-- | compiler/semexprs.nim | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 47e07d402..337224aef 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -299,7 +299,7 @@ proc semOf(c: PContext, n: PNode): PNode = n.typ = getSysType(tyBool) result = n -proc IsOpImpl(c: PContext, n: PNode): PNode = +proc isOpImpl(c: PContext, n: PNode): PNode = InternalAssert n.sonsLen == 3 and n[1].kind == nkSym and n[1].sym.kind == skType and n[2].kind in {nkStrLit..nkTripleStrLit, nkType} @@ -321,10 +321,19 @@ proc IsOpImpl(c: PContext, n: PNode): PNode = else: var match: bool let t2 = n[2].typ - if t2.kind == tyTypeClass: + case t2.kind + of tyTypeClass: var m: TCandidate InitCandidate(m, t2) match = matchUserTypeClass(c, m, emptyNode, t2, t1) != nil + of tyOrdinal: + var m: TCandidate + InitCandidate(m, t2) + match = isOrdinalType(t1) + of tySequence, tyArray, tySet: + var m: TCandidate + InitCandidate(m, t2) + match = typeRel(m, t2, t1) != isNone else: match = sameType(t1, t2) @@ -353,7 +362,7 @@ proc semIs(c: PContext, n: PNode): PNode = let t1 = n[1].typ.sons[0] # BUGFIX: don't evaluate this too early: ``T is void`` - if not containsGenericType(t1): result = IsOpImpl(c, n) + if not containsGenericType(t1): result = isOpImpl(c, n) proc semOpAux(c: PContext, n: PNode) = const flags = {efDetermineType} @@ -763,7 +772,8 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode = analyseIfAddressTakenInCall(c, result) if callee.magic != mNone: result = magicsAfterOverloadResolution(c, result, flags) - result = evalAtCompileTime(c, result) + if c.InTypeClass == 0: + result = evalAtCompileTime(c, result) proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode = # this seems to be a hotspot in the compiler! @@ -814,7 +824,7 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode = proc semExprNoType(c: PContext, n: PNode): PNode = result = semExpr(c, n, {efWantStmt}) - discardCheck(result) + discardCheck(c, result) proc isTypeExpr(n: PNode): bool = case n.kind @@ -1208,7 +1218,7 @@ proc semProcBody(c: PContext, n: PNode): PNode = a.sons[1] = result result = semAsgn(c, a) else: - discardCheck(result) + discardCheck(c, result) closeScope(c) proc SemYieldVarResult(c: PContext, n: PNode, restype: PType) = @@ -1429,12 +1439,12 @@ proc semQuoteAst(c: PContext, n: PNode): PNode = newNode(nkCall, n.info, quotes)]) result = semExpandToAst(c, result) -proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = +proc tryExpr(c: PContext, n: PNode, + flags: TExprFlags = {}, bufferErrors = false): PNode = # watch out, hacks ahead: let oldErrorCount = msgs.gErrorCounter let oldErrorMax = msgs.gErrorMax inc c.InCompilesContext - inc msgs.gSilence # do not halt after first error: msgs.gErrorMax = high(int) @@ -1443,6 +1453,8 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = openScope(c) let oldOwnerLen = len(gOwners) let oldGenerics = c.generics + let oldErrorOutputs = errorOutputs + errorOutputs = if bufferErrors: {eInMemory} else: {} let oldContextLen = msgs.getInfoContextLen() let oldInGenericContext = c.InGenericContext @@ -1465,7 +1477,7 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = setlen(gOwners, oldOwnerLen) c.currentScope = oldScope dec c.InCompilesContext - dec msgs.gSilence + errorOutputs = oldErrorOutputs msgs.gErrorCounter = oldErrorCount msgs.gErrorMax = oldErrorMax |