diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-06-19 20:44:28 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-06-20 11:29:42 +0200 |
commit | 16eb4b1fee14e41807ff5c368ea848b71f258182 (patch) | |
tree | 801d23bfcbc8377f54f2986ec5fa9d34003e4645 /tests | |
parent | 8f4b3743277119a0ec231738fdd3931476c186d9 (diff) | |
download | Nim-16eb4b1fee14e41807ff5c368ea848b71f258182.tar.gz |
Fix #5127
Diffstat (limited to 'tests')
-rw-r--r-- | tests/concepts/texplain.nim | 18 | ||||
-rw-r--r-- | tests/concepts/tgraph.nim | 39 | ||||
-rw-r--r-- | tests/concepts/twrapconcept.nim | 22 |
3 files changed, 53 insertions, 26 deletions
diff --git a/tests/concepts/texplain.nim b/tests/concepts/texplain.nim index 25a075fd1..417d1e502 100644 --- a/tests/concepts/texplain.nim +++ b/tests/concepts/texplain.nim @@ -9,33 +9,33 @@ 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: type class predicate failed +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: type class predicate failed +texplain.nim(65, 5) ExplainedConcept: concept predicate failed texplain.nim(105, 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: type class predicate failed +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: type class predicate failed +texplain.nim(65, 5) ExplainedConcept: concept predicate failed texplain.nim(109, 20) Error: type mismatch: got (NonMatchingType) but expected one of: proc e(o: ExplainedConcept): int -texplain.nim(65, 5) ExplainedConcept: type class predicate failed +texplain.nim(65, 5) ExplainedConcept: concept predicate failed proc e(i: int): int texplain.nim(110, 20) Error: type mismatch: got (NonMatchingType) but expected one of: proc r(o: RegularConcept): int -texplain.nim(69, 5) RegularConcept: type class predicate failed +texplain.nim(69, 5) RegularConcept: concept predicate failed proc r[T](a: SomeNumber; b: T; c: auto) proc r(i: string): int @@ -49,12 +49,12 @@ 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: type class predicate failed +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: type class predicate failed -texplain.nim(73, 5) NestedConcept: type class predicate failed +texplain.nim(69, 5) RegularConcept: concept predicate failed +texplain.nim(73, 5) NestedConcept: concept predicate failed ''' line: 119 errormsg: "type mismatch: got (MatchingType)" diff --git a/tests/concepts/tgraph.nim b/tests/concepts/tgraph.nim index a0177a043..985f04a61 100644 --- a/tests/concepts/tgraph.nim +++ b/tests/concepts/tgraph.nim @@ -1,29 +1,34 @@ -discard """ - output: '''XY is Node -MyGraph is Graph''' -""" # bug #3452 import math type - Node* = concept n - `==`(n, n) is bool + Node* = concept n + `==`(n, n) is bool - Graph* = concept g - var x: Node - distance(g, x, x) is float + Graph1* = concept g + type N = Node + distance(g, N, N) is float - XY* = tuple[x, y: int] + Graph2 = concept g + distance(g, Node, Node) is float - MyGraph* = object - points: seq[XY] + Graph3 = concept g + var x: Node + distance(g, x, x) is float -if XY is Node: - echo "XY is Node" + XY* = tuple[x, y: int] + + MyGraph* = object + points: seq[XY] + +static: + assert XY is Node proc distance*( g: MyGraph, a, b: XY): float = - sqrt( pow(float(a.x - b.x), 2) + pow(float(a.y - b.y), 2) ) + sqrt( pow(float(a.x - b.x), 2) + pow(float(a.y - b.y), 2) ) -if MyGraph is Graph: - echo "MyGraph is Graph" +static: + assert MyGraph is Graph1 + assert MyGraph is Graph2 + assert MyGraph is Graph3 diff --git a/tests/concepts/twrapconcept.nim b/tests/concepts/twrapconcept.nim new file mode 100644 index 000000000..25a855e34 --- /dev/null +++ b/tests/concepts/twrapconcept.nim @@ -0,0 +1,22 @@ +discard """ + errormsg: "type mismatch: got (string)" + line: 21 + nimout: "twrapconcept.nim(11, 5) Foo: concept predicate failed" +""" + +# https://github.com/nim-lang/Nim/issues/5127 + +type + Foo = concept foo + foo.get is int + + FooWrap[F: Foo] = object + foo: F + +proc get(x: int): int = x + +proc wrap[F: Foo](foo: F): FooWrap[F] = FooWrap[F](foo: foo) + +let x = wrap(12) +let y = wrap "string" + |