diff options
-rwxr-xr-x | compiler/ast.nim | 1 | ||||
-rwxr-xr-x | compiler/astalgo.nim | 5 | ||||
-rwxr-xr-x | compiler/lookups.nim | 9 | ||||
-rwxr-xr-x | compiler/msgs.nim | 2 | ||||
-rwxr-xr-x | compiler/parser.nim | 2 | ||||
-rwxr-xr-x | compiler/semcall.nim | 2 | ||||
-rwxr-xr-x | compiler/semdata.nim | 2 | ||||
-rwxr-xr-x | compiler/semexprs.nim | 1 | ||||
-rwxr-xr-x | compiler/semtypes.nim | 36 | ||||
-rwxr-xr-x | compiler/sigmatch.nim | 11 | ||||
-rwxr-xr-x | compiler/suggest.nim | 1 | ||||
-rwxr-xr-x | compiler/types.nim | 20 |
12 files changed, 56 insertions, 36 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 071318992..cd8154e46 100755 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -311,6 +311,7 @@ type const tyPureObject* = tyTuple GcTypeKinds* = {tyRef, tySequence, tyString} + tyError* = tyProxy # as an errornous node should match everything type TTypeKinds* = set[TTypeKind] diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 1f0633a1c..33c31c71d 100755 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -433,7 +433,9 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope = appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) of nkSym: appf(result, ",$N$1\"sym\": $2_$3", - [istr, toRope(n.sym.name.s), toRope(n.sym.id)]) + [istr, symToYaml(n.sym, indent, maxRecDepth), + toRope(n.sym.id)]) + #[istr, toRope(n.sym.name.s), toRope(n.sym.id)]) of nkIdent: if n.ident != nil: appf(result, ",$N$1\"ident\": $2", [istr, makeYamlString(n.ident.s)]) @@ -447,6 +449,7 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope = appf(result, "$N$1$2", [spaces(indent + 4), debugTree(n.sons[i], indent + 4, maxRecDepth - 1)]) appf(result, "$N$1]", [istr]) + appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)]) appf(result, "$N$1}", [spaces(indent)]) proc debug(n: PSym) = diff --git a/compiler/lookups.nim b/compiler/lookups.nim index dfabe5015..de546c959 100755 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -39,7 +39,14 @@ proc considerAcc*(n: PNode): PIdent = proc errorSym*(n: PNode): PSym = ## creates an error symbol to avoid cascading errors (for IDE support) - result = newSym(skUnknown, considerAcc(n), getCurrOwner()) + var m = n + # ensure that 'considerAcc' can't fail: + if m.kind == nkDotExpr: m = m.sons[1] + let ident = if m.kind in {nkIdent, nkSym, nkAccQuoted}: + considerAcc(m) + else: + getIdent("err:" & renderTree(m)) + result = newSym(skUnknown, ident, getCurrOwner()) result.info = n.info type diff --git a/compiler/msgs.nim b/compiler/msgs.nim index eb427954a..69c9154c7 100755 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -661,7 +661,7 @@ proc GlobalError*(info: TLineInfo, msg: TMsgKind, arg = "") = liMessage(info, msg, arg, doRaise) proc LocalError*(info: TLineInfo, msg: TMsgKind, arg = "") = - if gCmd == cmdIdeTools and gErrorCounter > 10: return + #if gCmd == cmdIdeTools and gErrorCounter > 10: return liMessage(info, msg, arg, doNothing) proc Message*(info: TLineInfo, msg: TMsgKind, arg = "") = diff --git a/compiler/parser.nim b/compiler/parser.nim index f78f07325..33a2b6aae 100755 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -274,8 +274,8 @@ proc exprList(p: var TParser, endTok: TTokType, result: PNode) = eat(p, endTok) proc dotExpr(p: var TParser, a: PNode): PNode = - getTok(p) var info = p.lex.getlineInfo + getTok(p) optInd(p, a) case p.tok.tokType of tkType: diff --git a/compiler/semcall.nim b/compiler/semcall.nim index da96c77cd..003500b57 100755 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -71,7 +71,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode, #writeMatches(alt) if c.inCompilesContext > 0: # quick error message for performance of 'compiles' built-in: - LocalError(n.Info, errAmbiguousCallXYZ, "") + GlobalError(n.Info, errAmbiguousCallXYZ, "") else: var args = "(" for i in countup(1, sonsLen(n) - 1): diff --git a/compiler/semdata.nim b/compiler/semdata.nim index ebae06ea1..f78672837 100755 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -228,7 +228,7 @@ proc newTypeS(kind: TTypeKind, c: PContext): PType = proc errorType*(c: PContext): PType = ## creates a type representing an error state - result = newTypeS(tyEmpty, c) + result = newTypeS(tyError, c) proc fillTypeS(dest: PType, kind: TTypeKind, c: PContext) = dest.kind = kind diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 1ed1776ee..4411385b4 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -995,6 +995,7 @@ proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode = analyseIfAddressTakenInCall(c, result) else: LocalError(n.Info, errUndeclaredFieldX, id.s) + result = emptyNode proc takeImplicitAddr(c: PContext, n: PNode): PNode = case n.kind diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 8e3a4dda4..de6e6cb0e 100755 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -159,10 +159,10 @@ proc semRange(c: PContext, n: PNode, prev: PType): PType = if isRange(n[1]): result = semRangeAux(c, n[1], prev) else: LocalError(n.sons[0].info, errRangeExpected) - result = errorType(c) + result = newOrPrevType(tyError, prev, c) else: LocalError(n.info, errXExpectsOneTypeParam, "range") - result = errorType(c) + result = newOrPrevType(tyError, prev, c) proc semArray(c: PContext, n: PNode, prev: PType): PType = var indx, base: PType @@ -182,7 +182,7 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType = addSonSkipIntLit(result, base) else: LocalError(n.info, errArrayExpectsTwoTypeParams) - result = errorType(c) + result = newOrPrevType(tyError, prev, c) proc semOrdinal(c: PContext, n: PNode, prev: PType): PType = result = newOrPrevType(tyOrdinal, prev, c) @@ -194,7 +194,7 @@ proc semOrdinal(c: PContext, n: PNode, prev: PType): PType = addSonSkipIntLit(result, base) else: LocalError(n.info, errXExpectsOneTypeParam, "ordinal") - result = errorType(c) + result = newOrPrevType(tyError, prev, c) proc semTypeIdent(c: PContext, n: PNode): PSym = if n.kind == nkSym: @@ -518,7 +518,9 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType = if concreteBase.kind == tyObject and tfFinal notin concreteBase.flags: addInheritedFields(c, check, pos, concreteBase) else: - localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects) + if concreteBase.kind != tyError: + localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects) + base = nil if n.kind != nkObjectTy: InternalError(n.info, "semObjectNode") result = newOrPrevType(tyObject, prev, c) rawAddSon(result, base) @@ -730,15 +732,15 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = var isConcrete = true if s.typ == nil: LocalError(n.info, errCannotInstantiateX, s.name.s) - return errorType(c) + return newOrPrevType(tyError, prev, c) elif s.typ.kind != tyGenericBody: isConcrete = false elif s.typ.containerID == 0: InternalError(n.info, "semtypes.semGeneric") - return errorType(c) + return newOrPrevType(tyError, prev, c) elif sonsLen(n) != sonsLen(s.typ): LocalError(n.info, errWrongNumberOfArguments) - return errorType(c) + return newOrPrevType(tyError, prev, c) addSonSkipIntLit(result, s.typ) # iterate over arguments: for i in countup(1, sonsLen(n)-1): @@ -750,7 +752,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = if isConcrete: if s.ast == nil: LocalError(n.info, errCannotInstantiateX, s.name.s) - result = errorType(c) + result = newOrPrevType(tyError, prev, c) else: result = instGenericContainer(c, n, result) @@ -781,7 +783,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = if sonsLen(n) == 1: result = semTypeNode(c, n.sons[0], prev) else: LocalError(n.info, errTypeExpected) - result = errorType(c) + result = newOrPrevType(tyError, prev, c) of nkCallKinds: let op = n.sons[0].ident if op.id in {ord(wAnd), ord(wOr)} or op.s == "|": @@ -790,10 +792,10 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = t2 = semTypeNode(c, n.sons[2], nil) if t1 == nil: LocalError(n.sons[1].info, errTypeExpected) - result = errorType(c) + result = newOrPrevType(tyError, prev, c) elif t2 == nil: LocalError(n.sons[2].info, errTypeExpected) - result = errorType(c) + result = newOrPrevType(tyError, prev, c) else: result = newTypeS(tyTypeClass, c) result.addSonSkipIntLit(t1) @@ -826,7 +828,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = var s = semTypeIdent(c, n) if s.typ == nil: LocalError(n.info, errTypeExpected) - result = errorType(c) + result = newOrPrevType(tyError, prev, c) elif prev == nil: result = s.typ else: @@ -844,7 +846,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = markUsed(n, n.sym) else: LocalError(n.info, errTypeExpected) - result = errorType(c) + result = newOrPrevType(tyError, prev, c) of nkObjectTy: result = semObjectNode(c, n, prev) of nkTupleTy: result = semTuple(c, n, prev) of nkRefTy: result = semAnyRef(c, n, tyRef, prev) @@ -872,11 +874,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = of nkBlockType: result = semBlockType(c, n, prev) else: LocalError(n.info, errTypeExpected) - if prev != nil and prev.kind == tyForward: - prev.kind = tyProxy - result = prev - else: - result = errorType(c) + result = newOrPrevType(tyError, prev, c) proc setMagicType(m: PSym, kind: TTypeKind, size: int) = m.typ.kind = kind diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 9273d5add..6a5b6ff60 100755 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -160,8 +160,9 @@ proc concreteType(c: TCandidate, t: PType): PType = # proc sort[T](cmp: proc(a, b: T): int = cmp) if result.kind != tyGenericParam: break of tyGenericInvokation: - assert false - else: + InternalError("cannot resolve type: " & typeToString(t)) + result = t + else: result = t # Note: empty is valid here proc handleRange(f, a: PType, min, max: TTypeKind): TTypeRelation = @@ -538,7 +539,7 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation = if result == isGeneric: put(c.bindings, f, a) else: result = isNone - of tyExpr, tyStmt: + of tyExpr, tyStmt, tyProxy: result = isGeneric else: internalError("typeRel: " & $f.kind) @@ -648,6 +649,10 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType, if skipTypes(f, abstractVar).kind in {tyTuple}: result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c) of isNone: + # we test for this here to not slow down ``typeRel``: + if a.kind == tyProxy: + inc(m.genericMatches) + return copyTree(arg) result = userConvMatch(c, m, f, a, arg) # check for a base type match, which supports openarray[T] without [] # constructor in a call: diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 10d50a6b7..fb8a74ef5 100755 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -218,6 +218,7 @@ proc suggestExpr*(c: PContext, node: PNode) = var obj = safeSemExpr(c, n.sons[0]) suggestFieldAccess(c, obj, outputs) else: + #debug n suggestEverything(c, n, outputs) if optContext in gGlobalOptions: diff --git a/compiler/types.nim b/compiler/types.nim index 64525c73b..ce044c2eb 100755 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -402,7 +402,7 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string = "float", "float32", "float64", "float128", "uint", "uint8", "uint16", "uint32", "uint64", "bignum", "const ", - "!", "varargs[$1]", "iter[$1]", "proxy[$1]", "TypeClass" ] + "!", "varargs[$1]", "iter[$1]", "Error Type", "TypeClass" ] var t = typ result = "" if t == nil: return @@ -485,7 +485,7 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string = addSep(prag) add(prag, "thread") if len(prag) != 0: add(result, "{." & prag & ".}") - of tyVarargs, tyIter, tyProxy: + of tyVarargs, tyIter: result = typeToStr[t.kind] % typeToString(t.sons[0]) else: result = typeToStr[t.kind] @@ -929,16 +929,20 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool = result = typeAllowedAux(marker, t.sons[0], skVar) of tyPtr: result = typeAllowedAux(marker, t.sons[0], skVar) - of tyArrayConstr, tyTuple, tySet, tyConst, tyMutable, tyIter, tyProxy: - for i in countup(0, sonsLen(t) - 1): + of tyArrayConstr, tyTuple, tySet, tyConst, tyMutable, tyIter: + for i in countup(0, sonsLen(t) - 1): result = typeAllowedAux(marker, t.sons[i], kind) - if not result: break + if not result: break of tyObject: if kind == skConst: return false for i in countup(0, sonsLen(t) - 1): result = typeAllowedAux(marker, t.sons[i], kind) if not result: break if result and t.n != nil: result = typeAllowedNode(marker, t.n, kind) + of tyProxy: + # for now same as error node; we say it's a valid type as it should + # prevent cascading errors: + result = true proc typeAllowed(t: PType, kind: TSymKind): bool = var marker = InitIntSet() @@ -1076,10 +1080,10 @@ proc computeSizeAux(typ: PType, a: var biggestInt): biggestInt = if result < 0: return if a < maxAlign: a = maxAlign result = align(result, a) - of tyGenericInst, tyDistinct, tyGenericBody, tyMutable, tyConst, tyIter, - tyProxy: + of tyGenericInst, tyDistinct, tyGenericBody, tyMutable, tyConst, tyIter: result = computeSizeAux(lastSon(typ), a) - else: + of tyProxy: result = 1 + else: #internalError("computeSizeAux()") result = - 1 typ.size = result |