fix some regressions caused by tyTypeDesc[tyNone]

This commit is contained in:
Zahary Karadjov 2014-02-15 20:44:01 +02:00
commit c1f1f84194
6 changed files with 39 additions and 32 deletions

View file

@ -213,7 +213,6 @@ proc makeTypeDesc*(c: PContext, typ: PType): PType =
proc makeTypeSymNode*(c: PContext, typ: PType, info: TLineInfo): PNode = proc makeTypeSymNode*(c: PContext, typ: PType, info: TLineInfo): PNode =
let typedesc = makeTypeDesc(c, typ) let typedesc = makeTypeDesc(c, typ)
rawAddSon(typedesc, newTypeS(tyNone, c))
let sym = newSym(skType, idAnon, getCurrOwner(), info).linkTo(typedesc) let sym = newSym(skType, idAnon, getCurrOwner(), info).linkTo(typedesc)
return newSymNode(sym, info) return newSymNode(sym, info)

View file

@ -346,22 +346,21 @@ proc semIs(c: PContext, n: PNode): PNode =
result = n result = n
n.typ = getSysType(tyBool) n.typ = getSysType(tyBool)
n.sons[1] = semExprWithType(c, n[1], {efDetermineType}) n.sons[1] = semExprWithType(c, n[1], {efDetermineType, efWantIterator})
if n[2].kind notin {nkStrLit..nkTripleStrLit}: if n[2].kind notin {nkStrLit..nkTripleStrLit}:
let t2 = semTypeNode(c, n[2], nil) let t2 = semTypeNode(c, n[2], nil)
n.sons[2] = newNodeIT(nkType, n[2].info, t2) n.sons[2] = newNodeIT(nkType, n[2].info, t2)
if n[1].typ.kind != tyTypeDesc: let lhsType = n[1].typ
n.sons[1] = makeTypeSymNode(c, n[1].typ, n[1].info) if lhsType.kind != tyTypeDesc:
elif n[1].typ.sonsLen == 0: n.sons[1] = makeTypeSymNode(c, lhsType, n[1].info)
elif lhsType.base.kind == tyNone:
# this is a typedesc variable, leave for evals # this is a typedesc variable, leave for evals
return return
let t1 = n[1].typ.sons[0]
# BUGFIX: don't evaluate this too early: ``T is void`` # BUGFIX: don't evaluate this too early: ``T is void``
if not containsGenericType(t1): result = isOpImpl(c, n) if not n[1].typ.base.containsGenericType: result = isOpImpl(c, n)
proc semOpAux(c: PContext, n: PNode) = proc semOpAux(c: PContext, n: PNode) =
const flags = {efDetermineType} const flags = {efDetermineType}
@ -918,8 +917,8 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
var ty = n.sons[0].typ var ty = n.sons[0].typ
var f: PSym = nil var f: PSym = nil
result = nil result = nil
if isTypeExpr(n.sons[0]) or ty.kind == tyTypeDesc and ty.len == 1: if isTypeExpr(n.sons[0]) or ty.kind == tyTypeDesc and ty.base.kind != tyNone:
if ty.kind == tyTypeDesc: ty = ty.sons[0] if ty.kind == tyTypeDesc: ty = ty.base
case ty.kind case ty.kind
of tyEnum: of tyEnum:
# look up if the identifier belongs to the enum: # look up if the identifier belongs to the enum:

View file

@ -1030,9 +1030,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
if s.kind != skError: localError(n.info, errTypeExpected) if s.kind != skError: localError(n.info, errTypeExpected)
result = newOrPrevType(tyError, prev, c) result = newOrPrevType(tyError, prev, c)
elif s.kind == skParam and s.typ.kind == tyTypeDesc: elif s.kind == skParam and s.typ.kind == tyTypeDesc:
assert s.typ.len > 0 internalAssert s.typ.base.kind != tyNone and prev == nil
internalAssert prev == nil result = s.typ.base
result = s.typ.sons[0]
elif prev == nil: elif prev == nil:
result = s.typ result = s.typ
else: else:

View file

@ -866,7 +866,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
else: else:
internalAssert a.sons != nil and a.sons.len > 0 internalAssert a.sons != nil and a.sons.len > 0
c.typedescMatched = true c.typedescMatched = true
result = typeRel(c, f.sons[0], a.sons[0]) result = typeRel(c, f.base, a.base)
else: else:
result = isNone result = isNone
else: else:
@ -896,22 +896,20 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
result = isNone result = isNone
of tyTypeDesc: of tyTypeDesc:
if a.kind != tyTypeDesc: return isNone
var prev = PType(idTableGet(c.bindings, f)) var prev = PType(idTableGet(c.bindings, f))
if prev == nil: if prev == nil:
if a.kind == tyTypeDesc: if f.base.kind == tyNone:
if f.sons[0].kind == tyNone: result = isGeneric
result = isGeneric
else:
result = typeRel(c, f.sons[0], a.sons[0])
if result != isNone:
put(c.bindings, f, a)
else: else:
result = isNone result = typeRel(c, f.base, a.base)
if result != isNone:
put(c.bindings, f, a)
else: else:
internalAssert prev.sonsLen == 1
let toMatch = if tfUnresolved in f.flags: a let toMatch = if tfUnresolved in f.flags: a
else: a.sons[0] else: a.base
result = typeRel(c, prev.sons[0], toMatch) result = typeRel(c, prev.base, toMatch)
of tyStmt: of tyStmt:
result = isGeneric result = isGeneric
@ -1015,7 +1013,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, argType: PType,
argType = arg.typ argType = arg.typ
var var
a = if c.inTypeClass > 0: argType.skipTypes({tyTypeDesc}) a = if c.inTypeClass > 0: argType.skipTypes({tyTypeDesc, tyFieldAccessor})
else: argType else: argType
r = typeRel(m, f, a) r = typeRel(m, f, a)

View file

@ -431,8 +431,8 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
add(result, typeToString(t.sons[i])) add(result, typeToString(t.sons[i]))
add(result, ']') add(result, ']')
of tyTypeDesc: of tyTypeDesc:
if t.len == 0: result = "typedesc" if t.base.kind == tyNone: result = "typedesc"
else: result = "typedesc[" & typeToString(t.sons[0]) & "]" else: result = "typedesc[" & typeToString(t.base) & "]"
of tyStatic: of tyStatic:
internalAssert t.len > 0 internalAssert t.len > 0
result = "static[" & typeToString(t.sons[0]) & "]" result = "static[" & typeToString(t.sons[0]) & "]"
@ -1231,8 +1231,7 @@ proc computeSizeAux(typ: PType, a: var BiggestInt): BiggestInt =
of tyGenericInst, tyDistinct, tyGenericBody, tyMutable, tyConst, tyIter: of tyGenericInst, tyDistinct, tyGenericBody, tyMutable, tyConst, tyIter:
result = computeSizeAux(lastSon(typ), a) result = computeSizeAux(lastSon(typ), a)
of tyTypeDesc: of tyTypeDesc:
result = if typ.len == 1: computeSizeAux(typ.sons[0], a) result = computeSizeAux(typ.base, a)
else: szUnknownSize
of tyForward: return szIllegalRecursion of tyForward: return szIllegalRecursion
else: else:
#internalError("computeSizeAux()") #internalError("computeSizeAux()")
@ -1258,7 +1257,7 @@ proc containsGenericTypeIter(t: PType, closure: PObject): bool =
return true return true
if t.kind == tyTypeDesc: if t.kind == tyTypeDesc:
if t.sons[0].kind == tyNone: return true if t.base.kind == tyNone: return true
if containsGenericTypeIter(t.base, closure): return true if containsGenericTypeIter(t.base, closure): return true
return false return false

View file

@ -26,3 +26,16 @@ foo 10
foo "test" foo "test"
foo(@[TObj(x: 10), TObj(x: 20)]) foo(@[TObj(x: 10), TObj(x: 20)])
proc intval(x: int) = discard
# check real and virtual fields
type
TFoo = generic T
intval T.x
intval T.y
proc y(x: TObj): int = 10
proc testFoo(x: TFoo) = discard
testFoo(TObj(x: 10))