* Fix #5691
* Cleanup and thoughts
* Use scope approach
* Seperate defined/declared/declaredInScope magics
* Fix declaredInScope
* Update spec accordingly
This commit is contained in:
Clyybber 2020-08-27 15:50:59 +02:00 • committed by GitHub
commit fb58066b61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 180 additions and 85 deletions

View file

@ -22,6 +22,7 @@ a[1]: 45
x: some string
([("key", "val"), ("keyB", "2")], [("val", "key"), ("2", "keyB")])
([("key", "val"), ("keyB", "2")], [("val", "key"), ("2", "keyB")])
0
'''
"""
@ -222,3 +223,17 @@ block getImplTransformed:
doAssert "toExpand" notin code
# template is expanded (but that would already be the case with
# `a.getImpl.repr`, unlike the other transformations mentioned above
# test macro resemming
macro makeVar(): untyped =
quote:
var tensorY {.inject.}: int
macro noop(a: typed): untyped =
a
noop:
makeVar
echo tensorY

View file

@ -43,6 +43,8 @@ macro checkType(ex: typed): untyped =
echo ex.getTypeInst.repr, "; ", ex.typeKind, "; ", ex.getType.repr, "; ", ex.getTypeImpl.repr
macro checkProcType(fn: typed): untyped =
if fn.kind == nnkProcDef:
result = fn
let fn_sym = if fn.kind == nnkProcDef: fn[0] else: fn
echo fn_sym, "; ", fn_sym.typeKind, "; ", fn_sym.getType.repr, "; ", fn_sym.getTypeImpl.repr

View file

@ -336,3 +336,61 @@ test(hello):
var data = 5
hello(data)
# bug #5691
template bar(x: typed) = discard
macro barry(x: typed) = discard
var a = 0
bar:
var a = 10
barry:
var a = 20
bar:
var b = 10
barry:
var b = 20
var b = 30
# template bar(x: static int) = discard
#You may think that this should work:
# bar((var c = 1; echo "hey"; c))
# echo c
#But it must not! Since this would be incorrect:
# bar((var b = 3; const c = 1; echo "hey"; c))
# echo b # <- b wouldn't exist
discard not (let xx = 1; true)
discard xx
template barrel(a: typed): untyped = a
barrel:
var aa* = 1
var bb = 3
export bb
# Test declaredInScope within params
template test1: untyped =
when not declaredInScope(thing):
var thing {.inject.}: int
proc chunkedReadLoop =
test1
test1
template test2: untyped =
when not not not declaredInScope(thing):
var thing {.inject.}: int
proc chunkedReadLoop2 =
test2
test2
test1(); test2()

View file

@ -0,0 +1,10 @@
discard """
errormsg: "undeclared identifier: 'a'"
line: 10
"""
template secondArg(a, b: typed): untyped =
b
echo secondArg((var a = 1; 1), a)