fixes #429 and tstmtexpr
This commit is contained in:
parent
4005cd1fa3
commit
b3103c4657
6 changed files with 35 additions and 22 deletions
|
|
@ -177,7 +177,6 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) =
|
||||||
s = stream
|
s = stream
|
||||||
while true:
|
while true:
|
||||||
openParsers(p, fileIdx, s)
|
openParsers(p, fileIdx, s)
|
||||||
var code = p.parseAll
|
|
||||||
|
|
||||||
if sfSystemModule notin module.flags:
|
if sfSystemModule notin module.flags:
|
||||||
# XXX what about caching? no processing then? what if I change the
|
# XXX what about caching? no processing then? what if I change the
|
||||||
|
|
@ -187,7 +186,10 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) =
|
||||||
processImplicits implicitImports, nkImportStmt, a
|
processImplicits implicitImports, nkImportStmt, a
|
||||||
processImplicits implicitIncludes, nkIncludeStmt, a
|
processImplicits implicitIncludes, nkIncludeStmt, a
|
||||||
|
|
||||||
discard processTopLevelStmt(code, a)
|
while true:
|
||||||
|
var n = parseTopLevelStmt(p)
|
||||||
|
if n.kind == nkEmpty: break
|
||||||
|
if not processTopLevelStmt(n, a): break
|
||||||
|
|
||||||
closeParsers(p)
|
closeParsers(p)
|
||||||
if s.kind != llsStdIn: break
|
if s.kind != llsStdIn: break
|
||||||
|
|
|
||||||
|
|
@ -1671,11 +1671,17 @@ proc buildCall(n: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
|
proc doBlockIsStmtList(n: PNode): bool =
|
||||||
|
result = n.kind == nkDo and
|
||||||
|
n[paramsPos].sonsLen == 1 and
|
||||||
|
n[paramsPos][0].kind == nkEmpty
|
||||||
|
|
||||||
proc fixImmediateParams(n: PNode): PNode =
|
proc fixImmediateParams(n: PNode): PNode =
|
||||||
# XXX: Temporary work-around until we carry out
|
# XXX: Temporary work-around until we carry out
|
||||||
# the planned overload resolution reforms
|
# the planned overload resolution reforms
|
||||||
for i in 1 .. <safeLen(n):
|
for i in 1 .. <safeLen(n):
|
||||||
if n[i].kind == nkDo: n.sons[i] = n[i][bodyPos]
|
if doBlockIsStmtList(n[i]):
|
||||||
|
n.sons[i] = n[i][bodyPos]
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
proc semExport(c: PContext, n: PNode): PNode =
|
proc semExport(c: PContext, n: PNode): PNode =
|
||||||
|
|
|
||||||
|
|
@ -570,19 +570,17 @@ proc paramTypeClass(c: PContext, paramType: PType, procKind: TSymKind):
|
||||||
# if id is not nil, the generic param will bind just once (see below)
|
# if id is not nil, the generic param will bind just once (see below)
|
||||||
case paramType.kind:
|
case paramType.kind:
|
||||||
of tyExpr:
|
of tyExpr:
|
||||||
if procKind notin {skTemplate, skMacro}:
|
if paramType.sonsLen == 0:
|
||||||
if paramType.sonsLen == 0:
|
# proc(a, b: expr)
|
||||||
# proc(a, b: expr)
|
# no constraints, treat like generic param
|
||||||
# no constraints, treat like generic param
|
result.typ = newTypeS(tyGenericParam, c)
|
||||||
result.typ = newTypeS(tyGenericParam, c)
|
else:
|
||||||
else:
|
# proc(a: expr{string}, b: expr{nkLambda})
|
||||||
# proc(a: expr{string}, b: expr{nkLambda})
|
# overload on compile time values and AST trees
|
||||||
# overload on compile time values and AST trees
|
result.typ = newTypeS(tyExpr, c)
|
||||||
result.typ = newTypeS(tyExpr, c)
|
result.typ.sons = paramType.sons
|
||||||
result.typ.sons = paramType.sons
|
|
||||||
of tyTypeDesc:
|
of tyTypeDesc:
|
||||||
if procKind notin {skTemplate, skMacro} and
|
if tfInstantiated notin paramType.flags:
|
||||||
tfInstantiated notin paramType.flags:
|
|
||||||
result.typ = newTypeS(tyTypeDesc, c)
|
result.typ = newTypeS(tyTypeDesc, c)
|
||||||
result.typ.sons = paramType.sons
|
result.typ.sons = paramType.sons
|
||||||
of tyDistinct:
|
of tyDistinct:
|
||||||
|
|
@ -604,11 +602,16 @@ proc paramTypeClass(c: PContext, paramType: PType, procKind: TSymKind):
|
||||||
proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
paramType: PType, paramName: string,
|
paramType: PType, paramName: string,
|
||||||
info: TLineInfo): PType =
|
info: TLineInfo): PType =
|
||||||
|
result = paramType
|
||||||
|
if procKind in {skMacro, skTemplate}:
|
||||||
|
# generic param types in macros and templates affect overload
|
||||||
|
# resolution, but don't work as generic params when it comes
|
||||||
|
# to proc instantiation. We don't need to lift such params here.
|
||||||
|
return
|
||||||
## Params having implicit generic types or pseudo types such as 'expr'
|
## Params having implicit generic types or pseudo types such as 'expr'
|
||||||
## need to be added to the generic params lists.
|
## need to be added to the generic params lists.
|
||||||
## 'expr' is different from 'expr{string}' so we must first call
|
## 'expr' is different from 'expr{string}' so we must first call
|
||||||
## paramTypeClass to get the actual type we are going to use.
|
## paramTypeClass to get the actual type we are going to use.
|
||||||
result = paramType
|
|
||||||
var (typeClass, paramTypId) = paramTypeClass(c, paramType, procKind)
|
var (typeClass, paramTypId) = paramTypeClass(c, paramType, procKind)
|
||||||
let isAnon = paramTypId == nil
|
let isAnon = paramTypId == nil
|
||||||
if typeClass != nil:
|
if typeClass != nil:
|
||||||
|
|
|
||||||
|
|
@ -683,11 +683,12 @@ proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType,
|
||||||
proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
|
proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
|
||||||
arg, argOrig: PNode): PNode =
|
arg, argOrig: PNode): PNode =
|
||||||
var r: TTypeRelation
|
var r: TTypeRelation
|
||||||
if f.kind == tyExpr:
|
let fMaybeExpr = f.skipTypes({tyDistinct})
|
||||||
if f.sonsLen == 0:
|
if fMaybeExpr.kind == tyExpr:
|
||||||
|
if fMaybeExpr.sonsLen == 0:
|
||||||
r = isGeneric
|
r = isGeneric
|
||||||
else:
|
else:
|
||||||
let match = matchTypeClass(m, f, a)
|
let match = matchTypeClass(m, fMaybeExpr, a)
|
||||||
if match != isGeneric: r = isNone
|
if match != isGeneric: r = isNone
|
||||||
else:
|
else:
|
||||||
# XXX: Ideally, this should happen much earlier somewhere near
|
# XXX: Ideally, this should happen much earlier somewhere near
|
||||||
|
|
|
||||||
|
|
@ -1016,8 +1016,9 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
|
||||||
of tyExpr, tyStmt, tyTypeDesc:
|
of tyExpr, tyStmt, tyTypeDesc:
|
||||||
result = true
|
result = true
|
||||||
# XXX er ... no? these should not be allowed!
|
# XXX er ... no? these should not be allowed!
|
||||||
of tyGenericBody, tyGenericParam, tyForward, tyNone, tyGenericInvokation,
|
of tyTypeClass:
|
||||||
tyTypeClass:
|
result = true
|
||||||
|
of tyGenericBody, tyGenericParam, tyForward, tyNone, tyGenericInvokation:
|
||||||
result = false
|
result = false
|
||||||
of tyEmpty, tyNil:
|
of tyEmpty, tyNil:
|
||||||
result = kind == skConst
|
result = kind == skConst
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tstmtexp.nim"
|
file: "tstmtexp.nim"
|
||||||
line: 7
|
line: 8
|
||||||
errormsg: "value returned by statement has to be discarded"
|
errormsg: "value returned by statement has to be discarded"
|
||||||
"""
|
"""
|
||||||
# Test 3
|
# Test 3
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue