summary refs log tree commit diff stats
path: root/tests/objects
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-10-25 13:39:57 +0800
committerGitHub <noreply@github.com>2022-10-25 07:39:57 +0200
commitc1343739e15eb2b225d8a523d577c0bc84148ad9 (patch)
treee832212c6351f2884358a511b5dea04e3b226e40 /tests/objects
parent064b72a59c6ed61939fc89f91f4311ac60a6ec45 (diff)
downloadNim-c1343739e15eb2b225d8a523d577c0bc84148ad9.tar.gz
add type check for default fields (#20652)
Diffstat (limited to 'tests/objects')
-rw-r--r--tests/objects/tdefaultfieldscheck.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/objects/tdefaultfieldscheck.nim b/tests/objects/tdefaultfieldscheck.nim
new file mode 100644
index 000000000..9c648ed2b
--- /dev/null
+++ b/tests/objects/tdefaultfieldscheck.nim
@@ -0,0 +1,22 @@
+discard """
+  cmd: "nim check --hints:off $file"
+  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'
+'''
+"""
+
+type
+  Date* = object
+    name: int = "string"
+    time: string = 12
+    goal: float = 7
+    fun: int = 1.4
+
+echo default(Date)
\ No newline at end of file