From 94f2d639b18f71a4d17347ab134c155dc00cc788 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 25 Mar 2015 13:05:32 +0100 Subject: [PATCH] fixes #2401 --- compiler/ccgexprs.nim | 2 +- tests/method/temptybody.nim | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/method/temptybody.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 1ebf857712..e19341db5b 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1962,7 +1962,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) = var sym = n.sym case sym.kind of skMethod: - if sym.getBody.kind == nkEmpty or sfDispatcher in sym.flags: + if {sfDispatcher, sfForward} * sym.flags != {}: # we cannot produce code for the dispatcher yet: fillProcLoc(sym) genProcPrototype(p.module, sym) diff --git a/tests/method/temptybody.nim b/tests/method/temptybody.nim new file mode 100644 index 0000000000..26285d05b7 --- /dev/null +++ b/tests/method/temptybody.nim @@ -0,0 +1,11 @@ +# bug #2401 + +type MyClass = ref object of RootObj + +method HelloWorld*(obj: MyClass) = + when defined(myPragma): + echo("Hello World") + # discard # with this line enabled it works + +var obj = MyClass() +obj.HelloWorld()