fixes #3158
This commit is contained in:
parent
5e325bc9f9
commit
41e8c9b9ac
2 changed files with 25 additions and 1 deletions
|
|
@ -171,11 +171,15 @@ proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
result = newSym(kind, considerQuotedIdent(n), getCurrOwner(), n.info)
|
result = newSym(kind, considerQuotedIdent(n), getCurrOwner(), n.info)
|
||||||
|
|
||||||
proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
|
proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
|
proc `$`(kind: TSymKind): string = substr(system.`$`(kind), 2).toLower
|
||||||
|
|
||||||
# like newSymS, but considers gensym'ed symbols
|
# like newSymS, but considers gensym'ed symbols
|
||||||
if n.kind == nkSym:
|
if n.kind == nkSym:
|
||||||
# and sfGenSym in n.sym.flags:
|
# and sfGenSym in n.sym.flags:
|
||||||
result = n.sym
|
result = n.sym
|
||||||
internalAssert result.kind == kind
|
if result.kind != kind:
|
||||||
|
localError(n.info, "cannot use symbol of kind '" &
|
||||||
|
$result.kind & "' as a '" & $kind & "'")
|
||||||
# when there is a nested proc inside a template, semtmpl
|
# when there is a nested proc inside a template, semtmpl
|
||||||
# will assign a wrong owner during the first pass over the
|
# will assign a wrong owner during the first pass over the
|
||||||
# template; we must fix it here: see #909
|
# template; we must fix it here: see #909
|
||||||
|
|
|
||||||
20
tests/template/twrongsymkind.nim
Normal file
20
tests/template/twrongsymkind.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "cannot use symbol of kind 'var' as a 'param'"
|
||||||
|
line: 20
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #3158
|
||||||
|
|
||||||
|
type
|
||||||
|
MyData = object
|
||||||
|
x: int
|
||||||
|
|
||||||
|
template newDataWindow(data: ref MyData): stmt =
|
||||||
|
proc testProc(data: ref MyData) =
|
||||||
|
echo "Hello, ", data.x
|
||||||
|
testProc(data)
|
||||||
|
|
||||||
|
var d: ref MyData
|
||||||
|
new(d)
|
||||||
|
d.x = 10
|
||||||
|
newDataWindow(d)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue