fixes #6946
This commit is contained in:
parent
fc52dd6463
commit
fa0f5d0238
3 changed files with 21 additions and 12 deletions
|
|
@ -215,12 +215,17 @@ proc semIdentVis(c: PContext, kind: TSymKind, n: PNode,
|
||||||
proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode,
|
proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode,
|
||||||
allowed: TSymFlags): PSym
|
allowed: TSymFlags): PSym
|
||||||
|
|
||||||
proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind) =
|
proc typeAllowedCheck(info: TLineInfo; typ: PType; kind: TSymKind;
|
||||||
let t = typeAllowed(typ, kind)
|
flags: TTypeAllowedFlags = {}) =
|
||||||
|
let t = typeAllowed(typ, kind, flags)
|
||||||
if t != nil:
|
if t != nil:
|
||||||
if t == typ: localError(info, "invalid type: '" & typeToString(typ) & "'")
|
if t == typ:
|
||||||
else: localError(info, "invalid type: '" & typeToString(t) &
|
localError(info, "invalid type: '" & typeToString(typ) &
|
||||||
"' in this context: '" & 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.} =
|
proc paramsTypeCheck(c: PContext, typ: PType) {.inline.} =
|
||||||
typeAllowedCheck(typ.n.info, typ, skProc)
|
typeAllowedCheck(typ.n.info, typ, skProc)
|
||||||
|
|
|
||||||
|
|
@ -534,7 +534,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
|
|
||||||
# this can only happen for errornous var statements:
|
# this can only happen for errornous var statements:
|
||||||
if typ == nil: continue
|
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)
|
liftTypeBoundOps(c, typ, a.info)
|
||||||
var tup = skipTypes(typ, {tyGenericInst, tyAlias, tySink})
|
var tup = skipTypes(typ, {tyGenericInst, tyAlias, tySink})
|
||||||
if a.kind == nkVarTuple:
|
if a.kind == nkVarTuple:
|
||||||
|
|
|
||||||
|
|
@ -1058,11 +1058,12 @@ proc commonSuperclass*(a, b: PType): PType =
|
||||||
y = y.sons[0]
|
y = y.sons[0]
|
||||||
|
|
||||||
type
|
type
|
||||||
TTypeAllowedFlag = enum
|
TTypeAllowedFlag* = enum
|
||||||
taField,
|
taField,
|
||||||
taHeap
|
taHeap,
|
||||||
|
taConcept
|
||||||
|
|
||||||
TTypeAllowedFlags = set[TTypeAllowedFlag]
|
TTypeAllowedFlags* = set[TTypeAllowedFlag]
|
||||||
|
|
||||||
proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||||
flags: TTypeAllowedFlags = {}): PType
|
flags: TTypeAllowedFlags = {}): PType
|
||||||
|
|
@ -1130,7 +1131,10 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||||
of tyVoid:
|
of tyVoid:
|
||||||
if taField notin flags: result = t
|
if taField notin flags: result = t
|
||||||
of tyTypeClasses:
|
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,
|
of tyGenericBody, tyGenericParam, tyGenericInvocation,
|
||||||
tyNone, tyForward, tyFromExpr:
|
tyNone, tyForward, tyFromExpr:
|
||||||
result = t
|
result = t
|
||||||
|
|
@ -1178,11 +1182,11 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||||
result = nil
|
result = nil
|
||||||
of tyUnused, tyOptAsRef: internalError("typeAllowedAux")
|
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
|
# returns 'nil' on success and otherwise the part of the type that is
|
||||||
# wrong!
|
# wrong!
|
||||||
var marker = initIntSet()
|
var marker = initIntSet()
|
||||||
result = typeAllowedAux(marker, t, kind, {})
|
result = typeAllowedAux(marker, t, kind, flags)
|
||||||
|
|
||||||
proc align(address, alignment: BiggestInt): BiggestInt =
|
proc align(address, alignment: BiggestInt): BiggestInt =
|
||||||
result = (address + (alignment - 1)) and not (alignment - 1)
|
result = (address + (alignment - 1)) and not (alignment - 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue