summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorjcosborn <jcosborn@users.noreply.github.com>2020-07-24 14:19:11 -0500
committerGitHub <noreply@github.com>2020-07-24 21:19:11 +0200
commitadd003a07435a862191334a7f105cb27ecb73d1d (patch)
tree2c86ebd7cd600db73a16db43a8be6c129bfdc964 /tests
parent4b93c61f0d783cbc1ce35d4494b533186595cdbd (diff)
downloadNim-add003a07435a862191334a7f105cb27ecb73d1d.tar.gz
fix assignment to converted concept type (#15051)
* fix assignment to converted concept type

* check for resolved concepts

* add extra test
Diffstat (limited to 'tests')
-rw-r--r--tests/concepts/tusertypeclasses2.nim54
1 files changed, 37 insertions, 17 deletions
diff --git a/tests/concepts/tusertypeclasses2.nim b/tests/concepts/tusertypeclasses2.nim
index ae05540cd..c9978f6ef 100644
--- a/tests/concepts/tusertypeclasses2.nim
+++ b/tests/concepts/tusertypeclasses2.nim
@@ -1,24 +1,44 @@
-type
-  hasFieldX = concept z
-    z.x is int
+block:
+  type
+    hasFieldX = concept z
+      z.x is int
 
-  obj_x = object
-    x: int
+    obj_x = object
+      x: int
 
-  ref_obj_x = ref object
-    x: int
+    ref_obj_x = ref object
+      x: int
 
-  ref_to_obj_x = ref obj_x
+    ref_to_obj_x = ref obj_x
 
-  p_o_x = ptr obj_x
-  v_o_x = var obj_x
+    p_o_x = ptr obj_x
+    v_o_x = var obj_x
 
-template check(x) =
-  static: assert(x)
+  template check(x) =
+    static: assert(x)
 
-check obj_x is hasFieldX
-check ref_obj_x is hasFieldX
-check ref_to_obj_x is hasFieldX
-check p_o_x is hasFieldX
-check v_o_x is hasFieldX
+  check obj_x is hasFieldX
+  check ref_obj_x is hasFieldX
+  check ref_to_obj_x is hasFieldX
+  check p_o_x is hasFieldX
+  check v_o_x is hasFieldX
 
+block:
+  type
+    Foo = concept x
+      x.isFoo
+    Bar = distinct float
+  template isFoo(x: Bar): untyped = true
+  proc foo(x: var Foo) =
+    float(x) = 1.0
+  proc foo2(x: var Bar) =
+    float(x) = 1.0
+  proc foo3(x: var (Bar|SomeNumber)) =
+    float(x) = 1.0
+  proc foo4(x: var any) =
+    float(x) = 1.0
+  var x: Bar
+  foo(x)
+  foo2(x)
+  foo3(x)
+  foo4(x)