summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-11-14 22:59:37 +0800
committerGitHub <noreply@github.com>2022-11-14 15:59:37 +0100
commitd901d3b8c564f65b4f2596543b4adaf38fc57327 (patch)
tree271e1948b34b64a0e3d861b1dda4b5be66dea979
parent3eef0491a8ef904abdfe96ab97c566c794305d80 (diff)
downloadNim-d901d3b8c564f65b4f2596543b4adaf38fc57327.tar.gz
fixes #20836; fixes #20833; fixes `unsafeNew` (#20841)
* fixes #20836; fixes `unsafeNew`

* fixes #20833
-rw-r--r--compiler/semmagic.nim5
-rw-r--r--tests/objects/tunsafenew.nim10
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim
index 9e484e214..751ca8fe7 100644
--- a/compiler/semmagic.nim
+++ b/compiler/semmagic.nim
@@ -586,7 +586,10 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
     else:
       result = plugin(c, n)
   of mNew:
-    result = addDefaultFieldForNew(c, n)
+    if n[0].sym.name.s == "unsafeNew": # special case for unsafeNew
+      result = n
+    else:
+      result = addDefaultFieldForNew(c, n)
   of mNewFinalize:
     result = semNewFinalize(c, n)
   of mDestroy:
diff --git a/tests/objects/tunsafenew.nim b/tests/objects/tunsafenew.nim
new file mode 100644
index 000000000..6c1b33cd9
--- /dev/null
+++ b/tests/objects/tunsafenew.nim
@@ -0,0 +1,10 @@
+discard """
+  errormsg: "conversion from int literal(-1) to Natural is invalid"
+"""
+
+type
+  Obj = object
+    case b: bool
+    else: discard
+var o: ref Obj
+unsafeNew(o, -1)
\ No newline at end of file