summary refs log tree commit diff stats
path: root/tests/concepts
diff options
context:
space:
mode:
authorDaniil Yarancev <21169548+Yardanico@users.noreply.github.com>2018-01-07 21:02:00 +0300
committerGitHub <noreply@github.com>2018-01-07 21:02:00 +0300
commitfb44c522e6173528efa8035ecc459c84887d0167 (patch)
treea2f5e98606be265981a5f72748896967033e23d7 /tests/concepts
parentccf99fa5ce4fe992fb80dc89271faa51456c3fa5 (diff)
parente23ea64c41e101d4e1d933f0b015f51cc6c2f7de (diff)
downloadNim-fb44c522e6173528efa8035ecc459c84887d0167.tar.gz
Merge pull request #1 from nim-lang/devel
upstream
Diffstat (limited to 'tests/concepts')
-rw-r--r--tests/concepts/t1128.nim4
-rw-r--r--tests/concepts/t3330.nim2
-rw-r--r--tests/concepts/t6462.nim23
-rw-r--r--tests/concepts/tcomparable.nim13
-rw-r--r--tests/concepts/texplain.nim84
-rw-r--r--tests/concepts/tinfrecursion.nim13
-rw-r--r--tests/concepts/titerable.nim20
-rw-r--r--tests/concepts/tmapconcept.nim2
-rw-r--r--tests/concepts/tmisc_issues.nim6
9 files changed, 120 insertions, 47 deletions
diff --git a/tests/concepts/t1128.nim b/tests/concepts/t1128.nim
index 7f7525a13..69a2fa9b7 100644
--- a/tests/concepts/t1128.nim
+++ b/tests/concepts/t1128.nim
@@ -4,8 +4,8 @@ discard """
 
 type
   TFooContainer[T] = object
-  
-  TContainer[T] = generic var c
+
+  TContainer[T] = concept var c
     foo(c, T)
 
 proc foo[T](c: var TFooContainer[T], val: T) =
diff --git a/tests/concepts/t3330.nim b/tests/concepts/t3330.nim
index fcd5054ef..722c0a0e0 100644
--- a/tests/concepts/t3330.nim
+++ b/tests/concepts/t3330.nim
@@ -6,10 +6,10 @@ but expected one of:
 proc test(foo: Foo[int])
 t3330.nim(25, 8) Hint: Non-matching candidates for add(k, string, T)
 proc add(x: var string; y: string)
+proc add(result: var string; x: float)
 proc add(x: var string; y: char)
 proc add(result: var string; x: int64)
 proc add(x: var string; y: cstring)
-proc add(result: var string; x: float)
 proc add[T](x: var seq[T]; y: openArray[T])
 proc add[T](x: var seq[T]; y: T)
 
diff --git a/tests/concepts/t6462.nim b/tests/concepts/t6462.nim
new file mode 100644
index 000000000..2fa2268f8
--- /dev/null
+++ b/tests/concepts/t6462.nim
@@ -0,0 +1,23 @@
+discard """
+  output: "true"
+"""
+
+import future
+
+type
+  FilterMixin*[T] = ref object
+    test*:      (T) -> bool
+    trans*:     (T) -> T
+
+  SeqGen*[T] = ref object
+    fil*:     FilterMixin[T]
+  
+  WithFilter[T] = concept a
+    a.fil is FilterMixin[T]
+
+proc test*[T](a: WithFilter[T]): (T) -> bool =
+  a.fil.test
+
+var s = SeqGen[int](fil: FilterMixin[int](test: nil, trans: nil))
+echo s.test() == nil
+
diff --git a/tests/concepts/tcomparable.nim b/tests/concepts/tcomparable.nim
new file mode 100644
index 000000000..06612a47e
--- /dev/null
+++ b/tests/concepts/tcomparable.nim
@@ -0,0 +1,13 @@
+type
+  Comparable = concept a
+    (a < a) is bool
+
+proc myMax(a, b: Comparable): Comparable =
+  if a < b:
+    return b
+  else:
+    return a
+
+doAssert myMax(5, 10) == 10
+doAssert myMax(31.3, 1.23124) == 31.3
+
diff --git a/tests/concepts/texplain.nim b/tests/concepts/texplain.nim
index 417d1e502..de8ddf890 100644
--- a/tests/concepts/texplain.nim
+++ b/tests/concepts/texplain.nim
@@ -1,62 +1,66 @@
 discard """
   cmd: "nim c --verbosity:0 --colors:off $file"
   nimout: '''
-texplain.nim(99, 10) Hint: Non-matching candidates for e(y)
+texplain.nim(103, 10) Hint: Non-matching candidates for e(y)
 proc e(i: int): int
 
-texplain.nim(102, 7) Hint: Non-matching candidates for e(10)
+texplain.nim(106, 7) Hint: Non-matching candidates for e(10)
 proc e(o: ExplainedConcept): int
-texplain.nim(65, 6) ExplainedConcept: undeclared field: 'foo'
-texplain.nim(65, 6) ExplainedConcept: undeclared field: '.'
-texplain.nim(65, 6) ExplainedConcept: expression '.' cannot be called
-texplain.nim(65, 5) ExplainedConcept: concept predicate failed
-texplain.nim(66, 6) ExplainedConcept: undeclared field: 'bar'
-texplain.nim(66, 6) ExplainedConcept: undeclared field: '.'
-texplain.nim(66, 6) ExplainedConcept: expression '.' cannot be called
-texplain.nim(65, 5) ExplainedConcept: concept predicate failed
-
-texplain.nim(105, 10) Hint: Non-matching candidates for e(10)
+texplain.nim(69, 6) ExplainedConcept: undeclared field: 'foo'
+texplain.nim(69, 6) ExplainedConcept: undeclared field: '.'
+texplain.nim(69, 6) ExplainedConcept: expression '.' cannot be called
+texplain.nim(69, 5) ExplainedConcept: concept predicate failed
+texplain.nim(70, 6) ExplainedConcept: undeclared field: 'bar'
+texplain.nim(70, 6) ExplainedConcept: undeclared field: '.'
+texplain.nim(70, 6) ExplainedConcept: expression '.' cannot be called
+texplain.nim(69, 5) ExplainedConcept: concept predicate failed
+
+texplain.nim(109, 10) Hint: Non-matching candidates for e(10)
 proc e(o: ExplainedConcept): int
-texplain.nim(65, 6) ExplainedConcept: undeclared field: 'foo'
-texplain.nim(65, 6) ExplainedConcept: undeclared field: '.'
-texplain.nim(65, 6) ExplainedConcept: expression '.' cannot be called
-texplain.nim(65, 5) ExplainedConcept: concept predicate failed
-texplain.nim(66, 6) ExplainedConcept: undeclared field: 'bar'
-texplain.nim(66, 6) ExplainedConcept: undeclared field: '.'
-texplain.nim(66, 6) ExplainedConcept: expression '.' cannot be called
-texplain.nim(65, 5) ExplainedConcept: concept predicate failed
-
-texplain.nim(109, 20) Error: type mismatch: got (NonMatchingType)
-but expected one of: 
+texplain.nim(69, 6) ExplainedConcept: undeclared field: 'foo'
+texplain.nim(69, 6) ExplainedConcept: undeclared field: '.'
+texplain.nim(69, 6) ExplainedConcept: expression '.' cannot be called
+texplain.nim(69, 5) ExplainedConcept: concept predicate failed
+texplain.nim(70, 6) ExplainedConcept: undeclared field: 'bar'
+texplain.nim(70, 6) ExplainedConcept: undeclared field: '.'
+texplain.nim(70, 6) ExplainedConcept: expression '.' cannot be called
+texplain.nim(69, 5) ExplainedConcept: concept predicate failed
+
+texplain.nim(113, 20) Error: type mismatch: got (NonMatchingType)
+but expected one of:
 proc e(o: ExplainedConcept): int
-texplain.nim(65, 5) ExplainedConcept: concept predicate failed
+texplain.nim(69, 5) ExplainedConcept: concept predicate failed
 proc e(i: int): int
 
-texplain.nim(110, 20) Error: type mismatch: got (NonMatchingType)
-but expected one of: 
+expression: e(n)
+texplain.nim(114, 20) Error: type mismatch: got (NonMatchingType)
+but expected one of:
 proc r(o: RegularConcept): int
-texplain.nim(69, 5) RegularConcept: concept predicate failed
+texplain.nim(73, 5) RegularConcept: concept predicate failed
 proc r[T](a: SomeNumber; b: T; c: auto)
 proc r(i: string): int
 
-texplain.nim(111, 20) Hint: Non-matching candidates for r(y)
+expression: r(n)
+texplain.nim(115, 20) Hint: Non-matching candidates for r(y)
 proc r[T](a: SomeNumber; b: T; c: auto)
 proc r(i: string): int
 
-texplain.nim(119, 2) Error: type mismatch: got (MatchingType)
-but expected one of: 
+texplain.nim(123, 2) Error: type mismatch: got (MatchingType)
+but expected one of:
 proc f(o: NestedConcept)
-texplain.nim(69, 6) RegularConcept: undeclared field: 'foo'
-texplain.nim(69, 6) RegularConcept: undeclared field: '.'
-texplain.nim(69, 6) RegularConcept: expression '.' cannot be called
-texplain.nim(69, 5) RegularConcept: concept predicate failed
-texplain.nim(70, 6) RegularConcept: undeclared field: 'bar'
-texplain.nim(70, 6) RegularConcept: undeclared field: '.'
-texplain.nim(70, 6) RegularConcept: expression '.' cannot be called
-texplain.nim(69, 5) RegularConcept: concept predicate failed
-texplain.nim(73, 5) NestedConcept: concept predicate failed
+texplain.nim(73, 6) RegularConcept: undeclared field: 'foo'
+texplain.nim(73, 6) RegularConcept: undeclared field: '.'
+texplain.nim(73, 6) RegularConcept: expression '.' cannot be called
+texplain.nim(73, 5) RegularConcept: concept predicate failed
+texplain.nim(74, 6) RegularConcept: undeclared field: 'bar'
+texplain.nim(74, 6) RegularConcept: undeclared field: '.'
+texplain.nim(74, 6) RegularConcept: expression '.' cannot be called
+texplain.nim(73, 5) RegularConcept: concept predicate failed
+texplain.nim(77, 5) NestedConcept: concept predicate failed
+
+expression: f(y)
 '''
-  line: 119
+  line: 123
   errormsg: "type mismatch: got (MatchingType)"
 """
 
diff --git a/tests/concepts/tinfrecursion.nim b/tests/concepts/tinfrecursion.nim
new file mode 100644
index 000000000..60db410de
--- /dev/null
+++ b/tests/concepts/tinfrecursion.nim
@@ -0,0 +1,13 @@
+
+# bug #6691
+type
+  ConceptA = concept c
+
+  ConceptB = concept c
+      c.myProc(ConceptA)
+
+  Obj = object
+
+proc myProc(obj: Obj, x: ConceptA) = discard
+
+echo Obj is ConceptB
diff --git a/tests/concepts/titerable.nim b/tests/concepts/titerable.nim
new file mode 100644
index 000000000..b18658b2a
--- /dev/null
+++ b/tests/concepts/titerable.nim
@@ -0,0 +1,20 @@
+discard """
+  nimout: "int\nint"
+  output: 15
+"""
+
+import typetraits
+
+type
+  Iterable[T] = concept x
+    for value in x:
+      type(value) is T
+
+proc sum*[T](iter: Iterable[T]): T =
+  static: echo T.name
+  for element in iter:
+    static: echo element.type.name
+    result += element
+
+echo sum([1, 2, 3, 4, 5])
+
diff --git a/tests/concepts/tmapconcept.nim b/tests/concepts/tmapconcept.nim
index 81caed7c6..5082fcb61 100644
--- a/tests/concepts/tmapconcept.nim
+++ b/tests/concepts/tmapconcept.nim
@@ -1,7 +1,7 @@
 discard """
 output: '''10
 10
-nil
+
 1'''
 msg: '''
 K=string V=int
diff --git a/tests/concepts/tmisc_issues.nim b/tests/concepts/tmisc_issues.nim
index d9bb84a2f..662eba380 100644
--- a/tests/concepts/tmisc_issues.nim
+++ b/tests/concepts/tmisc_issues.nim
@@ -31,7 +31,7 @@ type ConcretePointOfFloat = object
 type ConcretePoint[Value] = object
   x, y: Value
 
-type AbstractPointOfFloat = generic p
+type AbstractPointOfFloat = concept p
   p.x is float and p.y is float
 
 let p1 = ConcretePointOfFloat(x: 0, y: 0)
@@ -89,10 +89,10 @@ type
   B = object
 
 proc size(self: B): int =
-  return -1  
+  return -1
 
 proc size(self: A): int =
-  return 0  
+  return 0
 
 let b = B()
 echo b is A