From c2e5faf959f006af67d1a054a92096d63eae192a Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 17 Sep 2018 19:14:13 +0200 Subject: [PATCH] The VM cannot call methods Fixes #2574 --- compiler/vmgen.nim | 3 +++ tests/vm/t2574.nim | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/vm/t2574.nim diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index e87347ec87..b6b5bf4f28 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1842,6 +1842,9 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) = let s = n.sons[0].sym if s.magic != mNone: genMagic(c, n, dest, s.magic) + elif s.kind == skMethod: + localError(c.config, n.info, "cannot call method " & s.name.s & + " at compile time") elif matches(s, "stdlib", "marshal", "to"): # XXX marshal load&store should not be opcodes, but use the # general callback mechanisms. diff --git a/tests/vm/t2574.nim b/tests/vm/t2574.nim new file mode 100644 index 0000000000..86602aeaf6 --- /dev/null +++ b/tests/vm/t2574.nim @@ -0,0 +1,14 @@ +discard """ + line: 14 + errormsg: "cannot call method eval at compile time" +""" + +type + PExpr = ref object of RootObj + +method eval(e: PExpr): int = + discard + +static: + let x = PExpr() + discard x.eval