fixes for the new overloading resolution

This commit is contained in:
Araq 2013-03-03 16:35:19 +01:00
commit 4b0cdc6db7
4 changed files with 14 additions and 21 deletions

View file

@ -1526,8 +1526,9 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
of mNewFinalize: genNewFinalize(p, e) of mNewFinalize: genNewFinalize(p, e)
of mNewSeq: genNewSeq(p, e) of mNewSeq: genNewSeq(p, e)
of mSizeOf: of mSizeOf:
let t = e.sons[1].typ.skipTypes({tyTypeDesc})
putIntoDest(p, d, e.typ, ropef("((NI)sizeof($1))", putIntoDest(p, d, e.typ, ropef("((NI)sizeof($1))",
[getTypeDesc(p.module, e.sons[1].typ)])) [getTypeDesc(p.module, t)]))
of mChr: genCast(p, e, d) of mChr: genCast(p, e, d)
of mOrd: genOrd(p, e, d) of mOrd: genOrd(p, e, d)
of mLengthArray, mHigh, mLengthStr, mLengthSeq, mLengthOpenArray: of mLengthArray, mHigh, mLengthStr, mLengthSeq, mLengthOpenArray:

View file

@ -86,10 +86,9 @@ proc GetUniqueType*(key: PType): PType =
if result == nil: if result == nil:
gCanonicalTypes[k] = key gCanonicalTypes[k] = key
result = key result = key
of tyGenericParam, tyTypeClass: of tyGenericParam, tyTypeClass, tyTypeDesc:
InternalError("GetUniqueType") InternalError("GetUniqueType")
of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, tyConst, tyIter, of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, tyConst, tyIter:
tyTypeDesc:
result = GetUniqueType(lastSon(key)) result = GetUniqueType(lastSon(key))
of tyArrayConstr, tyGenericInvokation, tyGenericBody, of tyArrayConstr, tyGenericInvokation, tyGenericBody,
tyOpenArray, tyArray, tySet, tyRange, tyTuple, tyOpenArray, tyArray, tySet, tyRange, tyTuple,

View file

@ -10,18 +10,6 @@
# this module does the semantic checking for expressions # this module does the semantic checking for expressions
# included from sem.nim # included from sem.nim
proc restoreOldStyleType(n: PNode) =
# semExprWithType used to return the same type
# for nodes such as (100) or (int).
# This is inappropriate. The type of the first expression
# should be "int", while the type of the second one should
# be typedesc(int).
#
# This is strictly for backward compatibility until
# the transition to types as first-class values is complete.
if n.typ.kind == tyTypeDesc and n.typ.sonsLen == 1:
n.typ = n.typ.sons[0]
proc semTemplateExpr(c: PContext, n: PNode, s: PSym, semCheck = true): PNode = proc semTemplateExpr(c: PContext, n: PNode, s: PSym, semCheck = true): PNode =
markUsed(n, s) markUsed(n, s)
pushInfoContext(n.info) pushInfoContext(n.info)

View file

@ -31,6 +31,11 @@ proc getIdentNode(n: PNode): PNode =
illFormedAst(n) illFormedAst(n)
result = n result = n
proc newSymNodeTypeDesc(s: PSym; info: TLineInfo): PNode =
result = newSymNode(s, info)
result.typ = newType(tyTypeDesc, s.owner)
result.typ.addSonSkipIntLit(s.typ)
proc semGenericStmt(c: PContext, n: PNode, flags: TSemGenericFlags, proc semGenericStmt(c: PContext, n: PNode, flags: TSemGenericFlags,
ctx: var TIntSet): PNode ctx: var TIntSet): PNode
proc semGenericStmtScope(c: PContext, n: PNode, proc semGenericStmtScope(c: PContext, n: PNode,
@ -63,12 +68,12 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym): PNode =
else: else:
result = symChoice(c, n, s, scOpen) result = symChoice(c, n, s, scOpen)
of skGenericParam: of skGenericParam:
result = newSymNode(s, n.info) result = newSymNodeTypeDesc(s, n.info)
of skParam: of skParam:
result = n result = n
of skType: of skType:
if (s.typ != nil) and (s.typ.kind != tyGenericParam): if (s.typ != nil) and (s.typ.kind != tyGenericParam):
result = newSymNode(s, n.info) result = newSymNodeTypeDesc(s, n.info)
else: else:
result = n result = n
else: result = newSymNode(s, n.info) else: result = newSymNode(s, n.info)
@ -157,12 +162,12 @@ proc semGenericStmt(c: PContext, n: PNode,
result.sons[0] = symChoice(c, n.sons[0], s, scOption) result.sons[0] = symChoice(c, n.sons[0], s, scOption)
first = 1 first = 1
of skGenericParam: of skGenericParam:
result.sons[0] = newSymNode(s, n.sons[0].info) result.sons[0] = newSymNodeTypeDesc(s, n.sons[0].info)
first = 1 first = 1
of skType: of skType:
# bad hack for generics: # bad hack for generics:
if (s.typ != nil) and (s.typ.kind != tyGenericParam): if (s.typ != nil) and (s.typ.kind != tyGenericParam):
result.sons[0] = newSymNode(s, n.sons[0].info) result.sons[0] = newSymNodeTypeDesc(s, n.sons[0].info)
first = 1 first = 1
else: else:
result.sons[0] = newSymNode(s, n.sons[0].info) result.sons[0] = newSymNode(s, n.sons[0].info)