Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
60 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
|