=> supports pragmas & names (+ changed behavior) (#14200)
* => supports pragmas & names (+ changed behavior) (x, y: int) is now parsed as (x: int, y: int) instead of (x: auto, y: int) inside => and ->. * fix pragma check * fixes, use since & LHS of -> supports pragmas
This commit is contained in:
parent
b56432bd8a
commit
3e060cfb0a
6 changed files with 96 additions and 55 deletions
|
|
@ -1,19 +1,16 @@
|
|||
discard """
|
||||
output: '''10
|
||||
10
|
||||
10
|
||||
3
|
||||
3
|
||||
output: '''
|
||||
noReturn
|
||||
6
|
||||
calling mystuff
|
||||
yes
|
||||
calling mystuff
|
||||
yes
|
||||
calling sugarWithPragma
|
||||
sugarWithPragma called
|
||||
'''
|
||||
"""
|
||||
|
||||
import future, macros
|
||||
import sugar, macros
|
||||
|
||||
proc twoParams(x: (int, int) -> int): int =
|
||||
result = x(5, 5)
|
||||
|
|
@ -30,23 +27,23 @@ proc noReturn(x: () -> void) =
|
|||
proc doWithOneAndTwo(f: (int, int) -> int): int =
|
||||
f(1,2)
|
||||
|
||||
echo twoParams(proc (a, b: auto): auto = a + b)
|
||||
echo twoParams((x, y) => x + y)
|
||||
|
||||
echo oneParam(x => x+5)
|
||||
|
||||
echo noParams(() => 3)
|
||||
|
||||
echo doWithOneAndTwo((x, y) => x + y)
|
||||
doAssert twoParams(proc (a, b: auto): auto = a + b) == 10
|
||||
doAssert twoParams((x, y) => x + y) == 10
|
||||
doAssert oneParam(x => x+5) == 10
|
||||
doAssert noParams(() => 3) == 3
|
||||
doAssert doWithOneAndTwo((x, y) => x + y) == 3
|
||||
|
||||
noReturn((() -> void) => echo("noReturn"))
|
||||
|
||||
proc pass2(f: (int, int) -> int): (int) -> int =
|
||||
((x: int) -> int) => f(2, x)
|
||||
|
||||
echo pass2((x, y) => x + y)(4)
|
||||
doAssert pass2((x, y) => x + y)(4) == 6
|
||||
|
||||
fun(x, y: int) {.noSideEffect.} => x + y
|
||||
|
||||
doAssert typeof(fun) is (proc (x, y: int): int {.nimcall.})
|
||||
doAssert fun(3, 4) == 7
|
||||
|
||||
proc register(name: string; x: proc()) =
|
||||
echo "calling ", name
|
||||
|
|
@ -72,3 +69,5 @@ macro m(x: untyped): untyped =
|
|||
m:
|
||||
proc mystuff() =
|
||||
echo "yes"
|
||||
|
||||
sugarWithPragma() {.m.} => echo "sugarWithPragma called"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue