mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-15 17:25:36 +00:00
fix broken => for typed procs with pragmas (#16190)
* fix broken => for typed procs with pragmas * add more sugar tests * add ending quote
This commit is contained in:
@@ -17,10 +17,7 @@ proc checkPragma(ex, prag: var NimNode) =
|
||||
since (1, 3):
|
||||
if ex.kind == nnkPragmaExpr:
|
||||
prag = ex[1]
|
||||
if ex[0].kind == nnkPar and ex[0].len == 1:
|
||||
ex = ex[0][0]
|
||||
else:
|
||||
ex = ex[0]
|
||||
ex = ex[0]
|
||||
|
||||
proc createProcType(p, b: NimNode): NimNode {.compileTime.} =
|
||||
result = newNimNode(nnkProcTy)
|
||||
@@ -66,12 +63,12 @@ macro `=>`*(p, b: untyped): untyped =
|
||||
|
||||
type
|
||||
Bot = object
|
||||
call: proc (): string {.nosideEffect.}
|
||||
call: proc (name: string): string {.noSideEffect.}
|
||||
|
||||
var myBot = Bot()
|
||||
|
||||
myBot.call = () {.nosideEffect.} => "I'm a bot."
|
||||
doAssert myBot.call() == "I'm a bot."
|
||||
myBot.call = (name: string) {.noSideEffect.} => "Hello " & name & ", I'm a bot."
|
||||
doAssert myBot.call("John") == "Hello John, I'm a bot."
|
||||
|
||||
var
|
||||
params = @[ident"auto"]
|
||||
@@ -89,7 +86,7 @@ macro `=>`*(p, b: untyped): untyped =
|
||||
checkPragma(p, pragma) # check again after -> transform
|
||||
|
||||
since (1, 3):
|
||||
if p.kind == nnkCall:
|
||||
if p.kind in {nnkCall, nnkObjConstr}:
|
||||
# foo(x, y) => x + y
|
||||
kind = nnkProcDef
|
||||
name = p[0]
|
||||
@@ -129,7 +126,7 @@ macro `=>`*(p, b: untyped): untyped =
|
||||
error("Expected proc type (->) got (" & c[0].strVal & ").", c)
|
||||
break
|
||||
else:
|
||||
error("Incorrect procedure parameter list.", c)
|
||||
error("Incorrect procedure parameter.", c)
|
||||
params.add(identDefs)
|
||||
of nnkIdent:
|
||||
var identDefs = newNimNode(nnkIdentDefs)
|
||||
|
||||
@@ -71,3 +71,16 @@ m:
|
||||
echo "yes"
|
||||
|
||||
sugarWithPragma() {.m.} => echo "sugarWithPragma called"
|
||||
|
||||
typedParamAndPragma(x, y: int) {.used.} -> int => x + y
|
||||
doAssert typedParamAndPragma(1, 2) == 3
|
||||
|
||||
type
|
||||
Bot = object
|
||||
call: proc (): string {.noSideEffect.}
|
||||
|
||||
var myBot = Bot()
|
||||
myBot.call = () {.noSideEffect.} => "I'm a bot."
|
||||
doAssert myBot.call() == "I'm a bot."
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user