summary refs log tree commit diff stats
path: root/tests/misc/tgenconstraints.nim
blob: 6e8fdc73864eb6ab765abd000575f2e7a8c632e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
discard """
  file: "tgenconstraints.nim"
  line: 25
  disabled: true
  errormsg: "cannot instantiate T2"
"""

type
  T1[T: int|string] = object
    x: T

  T2[T: Ordinal] = object
    x: T

var x1: T1[int]
var x2: T1[string]
var x3: T2[int]

proc foo[T](x: T): T2[T] {.discardable.} =
  var o: T1[T]

foo(10)

# XXX: allow type intersections in situation like this
proc bar(x: int|TNumber): T1[type(x)] {.discardable.} =
  when type(x) is TNumber:
    var o: T2[type(x)]

bar "test"
bar 100
bar 1.1
>body), &list) if err != nil { return res, fmt.Errorf("UnmarshalJson failed\n%s", err.Error()) } res = list.Photos[rand.Intn(len(list.Photos))] return res, nil } // GetJson takes reqInfo as input and returns the body and an error. func GetJson(reqInfo map[string]string) (string, error) { // reqInfo is map[string]string and params is built from it, // currently it takes apiKey and the date from reqInfo to // build param. If any new key/value is added to reqInfo then // it must be addded here too, it won't be sent as param // directly. params := make(map[string]string) params["format"] = "js" params["n"] = "1" // if random is true then fetch 7 photos if reqInfo["random"] == "true" { params["n"] = "7" } body, err := request.GetRes(reqInfo["api"], params) return string(body), err }