make some tests green
This commit is contained in:
parent
f0953db3ba
commit
49b0440c47
13 changed files with 45 additions and 30 deletions
|
|
@ -127,6 +127,9 @@ proc ensureNoMissingOrUnusedSymbols(scope: PScope) =
|
||||||
elif {sfUsed, sfExported} * s.flags == {} and optHints in s.options:
|
elif {sfUsed, sfExported} * s.flags == {} and optHints in s.options:
|
||||||
# BUGFIX: check options in s!
|
# BUGFIX: check options in s!
|
||||||
if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam}:
|
if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam}:
|
||||||
|
# XXX: implicit type params are currently skTypes
|
||||||
|
# maybe they can be made skGenericParam as well.
|
||||||
|
if s.typ != nil and tfImplicitTypeParam notin s.typ.flags:
|
||||||
message(s.info, hintXDeclaredButNotUsed, getSymRepr(s))
|
message(s.info, hintXDeclaredButNotUsed, getSymRepr(s))
|
||||||
s = nextIter(it, scope.symbols)
|
s = nextIter(it, scope.symbols)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -325,8 +325,13 @@ proc isOpImpl(c: PContext, n: PNode): PNode =
|
||||||
tfIterator notin t.flags))
|
tfIterator notin t.flags))
|
||||||
else:
|
else:
|
||||||
var t2 = n[2].typ.skipTypes({tyTypeDesc})
|
var t2 = n[2].typ.skipTypes({tyTypeDesc})
|
||||||
|
# XXX: liftParamType started to perform addDecl
|
||||||
|
# we could do that instead in semTypeNode by snooping for added
|
||||||
|
# gnrc. params, then it won't be necessary to open a new scope here
|
||||||
|
openScope(c)
|
||||||
let lifted = liftParamType(c, skType, newNodeI(nkArgList, n.info),
|
let lifted = liftParamType(c, skType, newNodeI(nkArgList, n.info),
|
||||||
t2, ":anon", n.info)
|
t2, ":anon", n.info)
|
||||||
|
closeScope(c)
|
||||||
if lifted != nil: t2 = lifted
|
if lifted != nil: t2 = lifted
|
||||||
var m: TCandidate
|
var m: TCandidate
|
||||||
initCandidate(c, m, t2)
|
initCandidate(c, m, t2)
|
||||||
|
|
@ -1258,7 +1263,8 @@ proc semProcBody(c: PContext, n: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
discardCheck(c, result)
|
discardCheck(c, result)
|
||||||
|
|
||||||
if c.p.resultSym != nil and c.p.resultSym.typ.isMetaType:
|
if c.p.owner.kind notin {skMacro, skTemplate} and
|
||||||
|
c.p.resultSym != nil and c.p.resultSym.typ.isMetaType:
|
||||||
localError(c.p.resultSym.info, errCannotInferReturnType)
|
localError(c.p.resultSym.info, errCannotInferReturnType)
|
||||||
|
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,9 @@ proc fixupInstantiatedSymbols(c: PContext, s: PSym) =
|
||||||
var oldPrc = c.generics[i].inst.sym
|
var oldPrc = c.generics[i].inst.sym
|
||||||
pushInfoContext(oldPrc.info)
|
pushInfoContext(oldPrc.info)
|
||||||
openScope(c)
|
openScope(c)
|
||||||
pushProcCon(c, oldPrc)
|
|
||||||
addProcDecls(c, oldPrc)
|
|
||||||
var n = oldPrc.ast
|
var n = oldPrc.ast
|
||||||
n.sons[bodyPos] = copyTree(s.getBody)
|
n.sons[bodyPos] = copyTree(s.getBody)
|
||||||
instantiateBody(c, n, oldPrc)
|
instantiateBody(c, n, oldPrc)
|
||||||
popProcCon(c)
|
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
popInfoContext()
|
popInfoContext()
|
||||||
|
|
||||||
|
|
@ -164,10 +161,11 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
# at this point semtypinst have to become part of sem, because it
|
# at this point semtypinst have to become part of sem, because it
|
||||||
# will need to use openScope, addDecl, etc
|
# will need to use openScope, addDecl, etc
|
||||||
#
|
#
|
||||||
|
addDecl(c, prc)
|
||||||
|
|
||||||
pushInfoContext(info)
|
pushInfoContext(info)
|
||||||
var cl = initTypeVars(c, pt, info)
|
var cl = initTypeVars(c, pt, info)
|
||||||
var result = instCopyType(cl, prc.typ)
|
var result = instCopyType(cl, prc.typ)
|
||||||
addDecl(c, prc)
|
|
||||||
let originalParams = result.n
|
let originalParams = result.n
|
||||||
result.n = originalParams.shallowCopy
|
result.n = originalParams.shallowCopy
|
||||||
|
|
||||||
|
|
@ -175,8 +173,12 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
|
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
|
||||||
propagateToOwner(result, result.sons[i])
|
propagateToOwner(result, result.sons[i])
|
||||||
let param = replaceTypeVarsN(cl, originalParams[i])
|
let param = replaceTypeVarsN(cl, originalParams[i])
|
||||||
internalAssert param.kind == nkSym
|
|
||||||
result.n.sons[i] = param
|
result.n.sons[i] = param
|
||||||
|
if param.kind == nkSym:
|
||||||
|
# XXX: this won't be true for void params
|
||||||
|
# implement pass-through of void params and
|
||||||
|
# the "sort by distance to point" container
|
||||||
|
param.sym.owner = prc
|
||||||
addDecl(c, param.sym)
|
addDecl(c, param.sym)
|
||||||
|
|
||||||
result.sons[0] = replaceTypeVarsT(cl, result.sons[0])
|
result.sons[0] = replaceTypeVarsT(cl, result.sons[0])
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType =
|
||||||
else:
|
else:
|
||||||
let e = semExprWithType(c, n.sons[1], {efDetermineType})
|
let e = semExprWithType(c, n.sons[1], {efDetermineType})
|
||||||
if e.typ.kind == tyFromExpr:
|
if e.typ.kind == tyFromExpr:
|
||||||
indx = e.typ
|
indx = makeRangeWithStaticExpr(c, e.typ.n)
|
||||||
elif e.kind in {nkIntLit..nkUInt64Lit}:
|
elif e.kind in {nkIntLit..nkUInt64Lit}:
|
||||||
indx = makeRangeType(c, 0, e.intVal-1, n.info, e.typ)
|
indx = makeRangeType(c, 0, e.intVal-1, n.info, e.typ)
|
||||||
elif e.kind == nkSym and e.typ.kind == tyStatic:
|
elif e.kind == nkSym and e.typ.kind == tyStatic:
|
||||||
|
|
@ -783,7 +783,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
result = paramType
|
result = paramType
|
||||||
result.lastSon.shouldHaveMeta
|
result.lastSon.shouldHaveMeta
|
||||||
|
|
||||||
let liftBody = liftingWalk(paramType.lastSon)
|
let liftBody = liftingWalk(paramType.lastSon, true)
|
||||||
if liftBody != nil:
|
if liftBody != nil:
|
||||||
result = liftBody
|
result = liftBody
|
||||||
result.shouldHaveMeta
|
result.shouldHaveMeta
|
||||||
|
|
@ -795,7 +795,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
|
|
||||||
let expanded = instGenericContainer(c, info, paramType,
|
let expanded = instGenericContainer(c, info, paramType,
|
||||||
allowMetaTypes = true)
|
allowMetaTypes = true)
|
||||||
result = liftingWalk(expanded)
|
result = liftingWalk(expanded, true)
|
||||||
|
|
||||||
of tyUserTypeClass, tyBuiltInTypeClass, tyAnd, tyOr, tyNot:
|
of tyUserTypeClass, tyBuiltInTypeClass, tyAnd, tyOr, tyNot:
|
||||||
result = addImplicitGeneric(copyType(paramType, getCurrOwner(), true))
|
result = addImplicitGeneric(copyType(paramType, getCurrOwner(), true))
|
||||||
|
|
@ -964,6 +964,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||||
elif s.typ.kind != tyGenericBody:
|
elif s.typ.kind != tyGenericBody:
|
||||||
#we likely got code of the form TypeA[TypeB] where TypeA is
|
#we likely got code of the form TypeA[TypeB] where TypeA is
|
||||||
#not generic.
|
#not generic.
|
||||||
|
debug s.typ
|
||||||
localError(n.info, errNoGenericParamsAllowedForX, s.name.s)
|
localError(n.info, errNoGenericParamsAllowedForX, s.name.s)
|
||||||
return newOrPrevType(tyError, prev, c)
|
return newOrPrevType(tyError, prev, c)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -522,8 +522,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
||||||
|
|
||||||
template bindingRet(res) =
|
template bindingRet(res) =
|
||||||
when res == isGeneric:
|
when res == isGeneric:
|
||||||
|
if doBind:
|
||||||
let bound = aOrig.skipTypes({tyRange}).skipIntLit
|
let bound = aOrig.skipTypes({tyRange}).skipIntLit
|
||||||
put(c.bindings, f, bound)
|
if doBind: put(c.bindings, f, bound)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
template considerPreviousT(body: stmt) {.immediate.} =
|
template considerPreviousT(body: stmt) {.immediate.} =
|
||||||
|
|
@ -869,7 +870,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
||||||
# any value" and what we need is "match any type", which can be encoded
|
# any value" and what we need is "match any type", which can be encoded
|
||||||
# by a tyTypeDesc params. Unfortunately, this requires more substantial
|
# by a tyTypeDesc params. Unfortunately, this requires more substantial
|
||||||
# changes in semtypinst and elsewhere.
|
# changes in semtypinst and elsewhere.
|
||||||
if a.kind == tyTypeDesc or tfWildcard in a.flags:
|
if tfWildcard in a.flags:
|
||||||
|
result = isGeneric
|
||||||
|
elif a.kind == tyTypeDesc:
|
||||||
if f.sonsLen == 0:
|
if f.sonsLen == 0:
|
||||||
result = isGeneric
|
result = isGeneric
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1569,7 +1569,7 @@ proc genProc(c: PCtx; s: PSym): int =
|
||||||
c.gABC(body, opcEof, eofInstr.regA)
|
c.gABC(body, opcEof, eofInstr.regA)
|
||||||
c.optimizeJumps(result)
|
c.optimizeJumps(result)
|
||||||
s.offset = c.prc.maxSlots
|
s.offset = c.prc.maxSlots
|
||||||
#if s.name.s == "xmlConstructor":
|
#if s.name.s == "foo":
|
||||||
# echo renderTree(body)
|
# echo renderTree(body)
|
||||||
# c.echoCode(result)
|
# c.echoCode(result)
|
||||||
c.prc = oldPrc
|
c.prc = oldPrc
|
||||||
|
|
|
||||||
|
|
@ -54,5 +54,5 @@ echo getRows(m)
|
||||||
type TTest[T: static[int], U: static[int]] = array[0..T*U, int]
|
type TTest[T: static[int], U: static[int]] = array[0..T*U, int]
|
||||||
type TTestSub[N: static[int]] = TTest[1, N]
|
type TTestSub[N: static[int]] = TTest[1, N]
|
||||||
|
|
||||||
var x: TTestSub[2]
|
var z: TTestSub[2]
|
||||||
echo x.high
|
echo z.high
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ 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
|
proc intval(x: int): int = 10
|
||||||
|
|
||||||
# check real and virtual fields
|
# check real and virtual fields
|
||||||
type
|
type
|
||||||
|
|
@ -34,7 +34,7 @@ type
|
||||||
T.x
|
T.x
|
||||||
y(T)
|
y(T)
|
||||||
intval T.y
|
intval T.y
|
||||||
let y = intval(T.y)
|
let z = intval(T.y)
|
||||||
|
|
||||||
proc y(x: TObj): int = 10
|
proc y(x: TObj): int = 10
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ type
|
||||||
rule: TNode ## the rule that the symbol refers to
|
rule: TNode ## the rule that the symbol refers to
|
||||||
TNode {.final, shallow.} = object
|
TNode {.final, shallow.} = object
|
||||||
case kind: TPegKind
|
case kind: TPegKind
|
||||||
of pkEmpty..pkWhitespace: discard
|
of pkEmpty..pkWhitespace: nil
|
||||||
of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: term: string
|
of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: term: string
|
||||||
of pkChar, pkGreedyRepChar: ch: char
|
of pkChar, pkGreedyRepChar: ch: char
|
||||||
of pkCharChoice, pkGreedyRepSet: charChoice: ref set[char]
|
of pkCharChoice, pkGreedyRepSet: charChoice: ref set[char]
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ proc addResult(r: var TResults, test: TTest,
|
||||||
expected = expected,
|
expected = expected,
|
||||||
given = given)
|
given = given)
|
||||||
r.data.addf("$#\t$#\t$#\t$#", name, expected, given, $success)
|
r.data.addf("$#\t$#\t$#\t$#", name, expected, given, $success)
|
||||||
|
echo " [", $success, "]"
|
||||||
|
|
||||||
proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest) =
|
proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest) =
|
||||||
if strip(expected.msg) notin strip(given.msg):
|
if strip(expected.msg) notin strip(given.msg):
|
||||||
|
|
@ -146,7 +147,7 @@ proc testSpec(r: var TResults, test: TTest) =
|
||||||
# major entry point for a single test
|
# major entry point for a single test
|
||||||
let tname = test.name.addFileExt(".nim")
|
let tname = test.name.addFileExt(".nim")
|
||||||
inc(r.total)
|
inc(r.total)
|
||||||
echo extractFilename(tname)
|
stdout.write extractFilename(tname)
|
||||||
var expected = parseSpec(tname)
|
var expected = parseSpec(tname)
|
||||||
if expected.err == reIgnored:
|
if expected.err == reIgnored:
|
||||||
r.addResult(test, "", "", reIgnored)
|
r.addResult(test, "", "", reIgnored)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
discard """
|
discard """
|
||||||
output: "Error: cannot evaluate at compile time: x"
|
errormsg: "cannot evaluate at compile time: x"
|
||||||
line: 10
|
line: 9
|
||||||
"""
|
"""
|
||||||
|
|
||||||
var x: array[100, char]
|
var x: array[100, char]
|
||||||
template Foo : expr = x[42]
|
template Foo : expr = x[42]
|
||||||
|
|
||||||
|
|
||||||
const myConst = foo
|
const myConst = foo
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
output: "Error: cannot evaluate at compile time: x"
|
errormsg: "cannot evaluate at compile time: x"
|
||||||
line: 7
|
line: 7
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue