summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-11-28 10:11:25 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-11-28 23:00:34 +0100
commit87f0d534d6da2e8a7dc390e47ba60ca4d8bfb759 (patch)
tree32ed920c2a6e178462b4f95e0506c7dc5905ada6
parent2dea9203791996f1c946c8f4708dc8ca5342180b (diff)
downloadNim-87f0d534d6da2e8a7dc390e47ba60ca4d8bfb759.tar.gz
fixes #12488 [backport]
-rw-r--r--compiler/vmgen.nim5
-rw-r--r--tests/vm/tmisc_vm.nim17
2 files changed, 21 insertions, 1 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index 17e9f8de3..18397ec26 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -2130,7 +2130,10 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
   of nkComesFrom:
     discard "XXX to implement for better stack traces"
   else:
-    globalError(c.config, n.info, "cannot generate VM code for " & $n)
+    if n.typ != nil and n.typ.isCompileTimeOnly:
+      genTypeLit(c, n.typ, dest)
+    else:
+      globalError(c.config, n.info, "cannot generate VM code for " & $n)
 
 proc removeLastEof(c: PCtx) =
   let last = c.code.len-1
diff --git a/tests/vm/tmisc_vm.nim b/tests/vm/tmisc_vm.nim
index a9a30568d..6eeecb869 100644
--- a/tests/vm/tmisc_vm.nim
+++ b/tests/vm/tmisc_vm.nim
@@ -15,6 +15,9 @@ Done!
 foo4
 foo4
 foo4
+(a: 0, b: 0)
+(a: 0, b: 0)
+(a: 0, b: 0)
 '''
 """
 
@@ -234,3 +237,17 @@ static:
   echo foo()
   echo foo()
   echo foo()
+
+# bug #12488
+type
+  MyObject = object
+    a,b: int
+  MyObjectRef = ref MyObject
+
+static:
+  let x1 = new(MyObject)
+  echo x1[]
+  let x2 = new(MyObjectRef)
+  echo x2[]
+  let x3 = new(ref MyObject) # cannot generate VM code for ref MyObject
+  echo x3[]