From fa0f5d0238d5656ace070b86ecc9cdec60568fdb Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 5 Feb 2018 21:21:22 +0100 Subject: [PATCH] fixes #6946 --- compiler/sem.nim | 15 ++++++++++----- compiler/semstmts.nim | 2 +- compiler/types.nim | 16 ++++++++++------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/compiler/sem.nim b/compiler/sem.nim index 0e97a66b2e..39b40b2e68 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -215,12 +215,17 @@ proc semIdentVis(c: PContext, kind: TSymKind, n: PNode, proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode, allowed: TSymFlags): PSym -proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind) = - let t = typeAllowed(typ, kind) +proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind; + flags: TTypeAllowedFlags = {}) = + let t = typeAllowed(typ, kind, flags) if t != nil: - if t == typ: localError(info, "invalid type: '" & typeToString(typ) & "'") - else: localError(info, "invalid type: '" & typeToString(t) & - "' in this context: '" & typeToString(typ) & "'") + if t == typ: + localError(info, "invalid type: '" & typeToString(typ) & + "' for " & substr($kind, 2).toLowerAscii) + else: + localError(info, "invalid type: '" & typeToString(t) & + "' in this context: '" & typeToString(typ) & + "' for " & substr($kind, 2).toLowerAscii) proc paramsTypeCheck(c: PContext, typ: PType) {.inline.} = typeAllowedCheck(typ.n.info, typ, skProc) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 74cca6d0c5..f4614272c5 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -534,7 +534,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = # this can only happen for errornous var statements: if typ == nil: continue - typeAllowedCheck(a.info, typ, symkind) + typeAllowedCheck(a.info, typ, symkind, if c.matchedConcept != nil: {taConcept} else: {}) liftTypeBoundOps(c, typ, a.info) var tup = skipTypes(typ, {tyGenericInst, tyAlias, tySink}) if a.kind == nkVarTuple: diff --git a/compiler/types.nim b/compiler/types.nim index cbbfa86317..452e95dfdc 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1058,11 +1058,12 @@ proc commonSuperclass*(a, b: PType): PType = y = y.sons[0] type - TTypeAllowedFlag = enum + TTypeAllowedFlag* = enum taField, - taHeap + taHeap, + taConcept - TTypeAllowedFlags = set[TTypeAllowedFlag] + TTypeAllowedFlags* = set[TTypeAllowedFlag] proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, flags: TTypeAllowedFlags = {}): PType @@ -1130,7 +1131,10 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, of tyVoid: if taField notin flags: result = t of tyTypeClasses: - if not (tfGenericTypeParam in t.flags or taField notin flags): result = t + if tfGenericTypeParam in t.flags or taConcept in flags: #or taField notin flags: + discard + elif kind notin {skParam, skResult}: + result = t of tyGenericBody, tyGenericParam, tyGenericInvocation, tyNone, tyForward, tyFromExpr: result = t @@ -1178,11 +1182,11 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, result = nil of tyUnused, tyOptAsRef: internalError("typeAllowedAux") -proc typeAllowed*(t: PType, kind: TSymKind): PType = +proc typeAllowed*(t: PType, kind: TSymKind; flags: TTypeAllowedFlags = {}): PType = # returns 'nil' on success and otherwise the part of the type that is # wrong! var marker = initIntSet() - result = typeAllowedAux(marker, t, kind, {}) + result = typeAllowedAux(marker, t, kind, flags) proc align(address, alignment: BiggestInt): BiggestInt = result = (address + (alignment - 1)) and not (alignment - 1)