fixes #433
This commit is contained in:
parent
8fd274038e
commit
9f6547ba63
4 changed files with 28 additions and 15 deletions
|
|
@ -40,15 +40,15 @@ proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
# do not produce another redundant error message:
|
# do not produce another redundant error message:
|
||||||
#raiseRecoverableError("")
|
#raiseRecoverableError("")
|
||||||
result = errorNode(c, n)
|
result = errorNode(c, n)
|
||||||
if result.typ != nil:
|
if isEmptyType(result.typ):
|
||||||
|
LocalError(n.info, errExprXHasNoType,
|
||||||
|
renderTree(result, {renderNoComments}))
|
||||||
|
result.typ = errorType(c)
|
||||||
|
else:
|
||||||
# XXX tyGenericInst here?
|
# XXX tyGenericInst here?
|
||||||
semProcvarCheck(c, result)
|
semProcvarCheck(c, result)
|
||||||
if result.typ.kind == tyVar: result = newDeref(result)
|
if result.typ.kind == tyVar: result = newDeref(result)
|
||||||
semDestructorCheck(c, result, flags)
|
semDestructorCheck(c, result, flags)
|
||||||
else:
|
|
||||||
LocalError(n.info, errExprXHasNoType,
|
|
||||||
renderTree(result, {renderNoComments}))
|
|
||||||
result.typ = errorType(c)
|
|
||||||
|
|
||||||
proc semExprNoDeref(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
proc semExprNoDeref(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
result = semExpr(c, n, flags)
|
result = semExpr(c, n, flags)
|
||||||
|
|
@ -233,7 +233,7 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
|
||||||
if sonsLen(n) != 2:
|
if sonsLen(n) != 2:
|
||||||
LocalError(n.info, errXExpectsTypeOrValue, opToStr[m])
|
LocalError(n.info, errXExpectsTypeOrValue, opToStr[m])
|
||||||
else:
|
else:
|
||||||
n.sons[1] = semExprWithType(c, n.sons[1])
|
n.sons[1] = semExprWithType(c, n.sons[1], {efDetermineType})
|
||||||
var typ = skipTypes(n.sons[1].typ, abstractVarRange)
|
var typ = skipTypes(n.sons[1].typ, abstractVarRange)
|
||||||
case typ.Kind
|
case typ.Kind
|
||||||
of tySequence, tyString, tyOpenArray, tyVarargs:
|
of tySequence, tyString, tyOpenArray, tyVarargs:
|
||||||
|
|
@ -250,7 +250,7 @@ proc semSizeof(c: PContext, n: PNode): PNode =
|
||||||
if sonsLen(n) != 2:
|
if sonsLen(n) != 2:
|
||||||
LocalError(n.info, errXExpectsTypeOrValue, "sizeof")
|
LocalError(n.info, errXExpectsTypeOrValue, "sizeof")
|
||||||
else:
|
else:
|
||||||
n.sons[1] = semExprWithType(c, n.sons[1])
|
n.sons[1] = semExprWithType(c, n.sons[1], {efDetermineType})
|
||||||
#restoreOldStyleType(n.sons[1])
|
#restoreOldStyleType(n.sons[1])
|
||||||
n.typ = getSysType(tyInt)
|
n.typ = getSysType(tyInt)
|
||||||
result = n
|
result = n
|
||||||
|
|
@ -258,7 +258,7 @@ proc semSizeof(c: PContext, n: PNode): PNode =
|
||||||
proc semOf(c: PContext, n: PNode): PNode =
|
proc semOf(c: PContext, n: PNode): PNode =
|
||||||
if sonsLen(n) == 3:
|
if sonsLen(n) == 3:
|
||||||
n.sons[1] = semExprWithType(c, n.sons[1])
|
n.sons[1] = semExprWithType(c, n.sons[1])
|
||||||
n.sons[2] = semExprWithType(c, n.sons[2])
|
n.sons[2] = semExprWithType(c, n.sons[2], {efDetermineType})
|
||||||
#restoreOldStyleType(n.sons[1])
|
#restoreOldStyleType(n.sons[1])
|
||||||
#restoreOldStyleType(n.sons[2])
|
#restoreOldStyleType(n.sons[2])
|
||||||
let a = skipTypes(n.sons[1].typ, abstractPtrs)
|
let a = skipTypes(n.sons[1].typ, abstractPtrs)
|
||||||
|
|
@ -297,7 +297,7 @@ 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])
|
n.sons[1] = semExprWithType(c, n[1], {efDetermineType})
|
||||||
if n[1].typ.kind != tyTypeDesc:
|
if n[1].typ.kind != tyTypeDesc:
|
||||||
LocalError(n[0].info, errTypeExpected)
|
LocalError(n[0].info, errTypeExpected)
|
||||||
|
|
||||||
|
|
@ -856,7 +856,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
if s != nil:
|
if s != nil:
|
||||||
return semSym(c, n, s, flags)
|
return semSym(c, n, s, flags)
|
||||||
|
|
||||||
n.sons[0] = semExprWithType(c, n.sons[0], flags)
|
n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType})
|
||||||
#restoreOldStyleType(n.sons[0])
|
#restoreOldStyleType(n.sons[0])
|
||||||
var i = considerAcc(n.sons[1])
|
var i = considerAcc(n.sons[1])
|
||||||
var ty = n.sons[0].typ
|
var ty = n.sons[0].typ
|
||||||
|
|
@ -1064,14 +1064,14 @@ proc semAsgn(c: PContext, n: PNode): PNode =
|
||||||
checkSonsLen(n, 2)
|
checkSonsLen(n, 2)
|
||||||
var a = n.sons[0]
|
var a = n.sons[0]
|
||||||
case a.kind
|
case a.kind
|
||||||
of nkDotExpr:
|
of nkDotExpr:
|
||||||
# r.f = x
|
# r.f = x
|
||||||
# --> `f=` (r, x)
|
# --> `f=` (r, x)
|
||||||
let nOrig = n.copyTree
|
let nOrig = n.copyTree
|
||||||
a = builtinFieldAccess(c, a, {efLValue})
|
a = builtinFieldAccess(c, a, {efLValue})
|
||||||
if a == nil:
|
if a == nil:
|
||||||
return propertyWriteAccess(c, n, nOrig, n[0])
|
return propertyWriteAccess(c, n, nOrig, n[0])
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
# a[i] = x
|
# a[i] = x
|
||||||
# --> `[]=`(a, i, x)
|
# --> `[]=`(a, i, x)
|
||||||
a = semSubscript(c, a, {efLValue})
|
a = semSubscript(c, a, {efLValue})
|
||||||
|
|
@ -1091,9 +1091,9 @@ proc semAsgn(c: PContext, n: PNode): PNode =
|
||||||
# a = b # b no 'var T' means: a = addr(b)
|
# a = b # b no 'var T' means: a = addr(b)
|
||||||
var le = a.typ
|
var le = a.typ
|
||||||
if skipTypes(le, {tyGenericInst}).kind != tyVar and
|
if skipTypes(le, {tyGenericInst}).kind != tyVar and
|
||||||
IsAssignable(c, a) == arNone:
|
IsAssignable(c, a) == arNone:
|
||||||
# Direct assignment to a discriminant is allowed!
|
# Direct assignment to a discriminant is allowed!
|
||||||
localError(a.info, errXCannotBeAssignedTo,
|
localError(a.info, errXCannotBeAssignedTo,
|
||||||
renderTree(a, {renderNoComments}))
|
renderTree(a, {renderNoComments}))
|
||||||
else:
|
else:
|
||||||
let
|
let
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ proc semDestructorCheck(c: PContext, n: PNode, flags: TExprFlags) {.inline.} =
|
||||||
if instantiateDestructor(c, n.typ):
|
if instantiateDestructor(c, n.typ):
|
||||||
LocalError(n.info, errGenerated,
|
LocalError(n.info, errGenerated,
|
||||||
"usage of a type with a destructor in a non destructible context")
|
"usage of a type with a destructor in a non destructible context")
|
||||||
|
if efDetermineType notin flags and n.typ.kind == tyTypeDesc:
|
||||||
|
localError(n.info, errGenerated, "value expected, but got a type")
|
||||||
|
|
||||||
proc newDeref(n: PNode): PNode {.inline.} =
|
proc newDeref(n: PNode): PNode {.inline.} =
|
||||||
result = newNodeIT(nkHiddenDeref, n.info, n.typ.sons[0])
|
result = newNodeIT(nkHiddenDeref, n.info, n.typ.sons[0])
|
||||||
|
|
|
||||||
10
tests/reject/ttypenovalue.nim
Normal file
10
tests/reject/ttypenovalue.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "value expected, but got a type"
|
||||||
|
line: 7
|
||||||
|
"""
|
||||||
|
|
||||||
|
proc crashAndBurn() =
|
||||||
|
var stuff = seq[tuple[title, body: string]]
|
||||||
|
|
||||||
|
|
||||||
|
crashAndBurn()
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -8,6 +8,7 @@ version 0.9.2
|
||||||
- mocking support with ``tyProxy`` that does: fallback for ``.`` operator
|
- mocking support with ``tyProxy`` that does: fallback for ``.`` operator
|
||||||
- overloading of ``.``? Special case ``.=``?
|
- overloading of ``.``? Special case ``.=``?
|
||||||
- built-in 'getImpl'
|
- built-in 'getImpl'
|
||||||
|
- macros.gensym still missing?
|
||||||
|
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue