summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-10-29 04:19:40 +0800
committerGitHub <noreply@github.com>2022-10-28 16:19:40 -0400
commit141abb7b75e1dcea8c138ba625831cce7e314e4a (patch)
tree837a9b1ac176b1181fda66e4c546f95b7fd266d3 /tests
parent779b1cc5beefa6064cb640401f1969c95a96c205 (diff)
downloadNim-141abb7b75e1dcea8c138ba625831cce7e314e4a.tar.gz
fixes #20681; add efSkipFieldVisibilityCheck to skip check (#20639)
* don't sem const objectConstr defaults

* fixes

* add `efSkipFieldVisibilityCheck`; fixes nkBracket types

* fixes #20681

* fixes tests

* suggestion from @metagn

* fixes tests

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/objects/tdefaultfieldscheck.nim9
-rw-r--r--tests/objects/tdefaultrangetypescheck.nim2
-rw-r--r--tests/objects/tobject_default_value.nim46
3 files changed, 28 insertions, 29 deletions
diff --git a/tests/objects/tdefaultfieldscheck.nim b/tests/objects/tdefaultfieldscheck.nim
index 9c648ed2b..d6feb2988 100644
--- a/tests/objects/tdefaultfieldscheck.nim
+++ b/tests/objects/tdefaultfieldscheck.nim
@@ -3,12 +3,9 @@ discard """
   errormsg: ""
   nimout:
 '''
-tdefaultfieldscheck.nim(17, 17) Error: type mismatch: got <string> but expected 'int'
-tdefaultfieldscheck.nim(18, 20) Error: type mismatch: got <int literal(12)> but expected 'string'
-tdefaultfieldscheck.nim(20, 16) Error: type mismatch: got <float64> but expected 'int'
-tdefaultfieldscheck.nim(17, 5) Error: type mismatch: got <string> but expected 'int'
-tdefaultfieldscheck.nim(18, 5) Error: type mismatch: got <int literal(12)> but expected 'string'
-tdefaultfieldscheck.nim(20, 5) Error: type mismatch: got <float64> but expected 'int'
+tdefaultfieldscheck.nim(14, 17) Error: type mismatch: got <string> but expected 'int'
+tdefaultfieldscheck.nim(15, 20) Error: type mismatch: got <int literal(12)> but expected 'string'
+tdefaultfieldscheck.nim(17, 16) Error: type mismatch: got <float64> but expected 'int'
 '''
 """
 
diff --git a/tests/objects/tdefaultrangetypescheck.nim b/tests/objects/tdefaultrangetypescheck.nim
index 50eeac492..71e7ac59b 100644
--- a/tests/objects/tdefaultrangetypescheck.nim
+++ b/tests/objects/tdefaultrangetypescheck.nim
@@ -1,5 +1,5 @@
 discard """
-  errormsg: "conversion from int literal(0) to range 1..5(int) is invalid"
+  errormsg: "cannot convert 0 to range 1..5(int)"
   line: 9
 """
 
diff --git a/tests/objects/tobject_default_value.nim b/tests/objects/tobject_default_value.nim
index efbce3658..643bba832 100644
--- a/tests/objects/tobject_default_value.nim
+++ b/tests/objects/tobject_default_value.nim
@@ -3,7 +3,7 @@ discard """
   targets: "c cpp js"
 """
 
-import times
+import std/[times, tables]
 
 type
   Guess = object
@@ -222,6 +222,18 @@ template main {.dirty.} =
         doAssert y.time == 1.2
         doAssert y.scale == 1
 
+      block:
+        var my = @[1, 2, 3, 4, 5]
+        my.setLen(0)
+        my.setLen(5)
+        doAssert my == @[0, 0, 0, 0, 0]
+
+      block:
+        var my = "hello"
+        my.setLen(0)
+        my.setLen(5)
+        doAssert $(@my) == """@['\x00', '\x00', '\x00', '\x00', '\x00']"""
+
   block: # array
     var x: array[10, Object] = arrayWith(default(Object), 10)
     let y = x[0]
@@ -379,7 +391,7 @@ template main {.dirty.} =
       doAssert x.id == 1
       doAssert x.obj == default(ObjectBase)
       doAssert x.name == ""
-    
+
     block:
       var x = default(Class)
       doAssert x.def == default(Default)
@@ -387,12 +399,11 @@ template main {.dirty.} =
       doAssert x.def.obj == default(ObjectBase)
       doAssert x.def.name == ""
 
-    when not defined(cpp):
-      block:
-        var x = default(Member)
-        doAssert x.def.id == 777
-        doAssert x.def.obj == default(ObjectBase)
-        doAssert x.def.name == "fine"
+    block:
+      var x = default(Member)
+      doAssert x.def.id == 777
+      doAssert x.def.obj == default(ObjectBase)
+      doAssert x.def.name == "fine"
 
   block:
     var x {.noinit.} = 12
@@ -408,22 +419,13 @@ template main {.dirty.} =
     var z {.noinit.}: Pure = Pure(id: 77)
     doAssert z.id == 77
 
+  block: # bug #20681
+    type A = object
+      d: DateTime = DateTime()
 
-proc main1 =
-  var my = @[1, 2, 3, 4, 5]
-  my.setLen(0)
-  my.setLen(5)
-  doAssert my == @[0, 0, 0, 0, 0]
-
-proc main2 =
-  var my = "hello"
-  my.setLen(0)
-  my.setLen(5)
-  doAssert $(@my) == """@['\x00', '\x00', '\x00', '\x00', '\x00']"""
+    let x = default(A)
+    doAssert $x == "(d: Uninitialized DateTime)"
 
-when defined(gcArc) or defined(gcOrc):
-  main1()
-  main2()
 
 static: main()
 main()