summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-08-10 12:06:16 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-08-10 12:06:16 +0200
commit404de2f23e931f922f283faa6d3491bfe3c0e68e (patch)
tree79ed71c485de952680a02a653f81ce00cc4da531 /tests
parent1d78ba64b4761de88817a2e5748a456679cb2bab (diff)
parent43f634db8dfac4fb13c8454958d35e776410dac1 (diff)
downloadNim-404de2f23e931f922f283faa6d3491bfe3c0e68e.tar.gz
Merge branch 'devel' into araq-misc
Diffstat (limited to 'tests')
-rw-r--r--tests/generics/t6137.nim29
-rw-r--r--tests/generics/t7141.nim10
-rw-r--r--tests/metatype/ttypeselectors.nim12
-rw-r--r--tests/stdlib/tsugar.nim29
4 files changed, 80 insertions, 0 deletions
diff --git a/tests/generics/t6137.nim b/tests/generics/t6137.nim
new file mode 100644
index 000000000..639675f35
--- /dev/null
+++ b/tests/generics/t6137.nim
@@ -0,0 +1,29 @@
+discard """
+  action: "reject"
+  line: 29
+  errormsg: "\'vectFunc\' doesn't have a concrete type, due to unspecified generic parameters."
+"""
+
+type
+  # simple vector of declared fixed length
+  vector[N : static[int]] = array[0..N-1, float]
+
+proc `*`[T](x: float, a: vector[T]): vector[T] =
+  # multiplication by scalar
+  for ii in 0..high(a):
+    result[ii] = a[ii]*x
+
+let
+  # define a vector of length 3
+  x: vector[3] = [1.0, 3.0, 5.0]
+
+proc vectFunc[T](x: vector[T]): vector[T] {.procvar.} =
+  # Define a vector function
+  result = 2.0*x
+
+proc passVectFunction[T](g: proc(x: vector[T]): vector[T], x: vector[T]): vector[T] =
+  # pass a vector function as input in another procedure
+  result = g(x)
+
+let
+  xNew = passVectFunction(vectFunc,x)
diff --git a/tests/generics/t7141.nim b/tests/generics/t7141.nim
new file mode 100644
index 000000000..8a128d828
--- /dev/null
+++ b/tests/generics/t7141.nim
@@ -0,0 +1,10 @@
+discard """
+  action: "reject"
+  line: 7
+  errormsg: "cannot instantiate: \'T\'"
+"""
+
+proc foo[T](x: T) =
+  discard
+
+var fun = if true: foo else: foo
diff --git a/tests/metatype/ttypeselectors.nim b/tests/metatype/ttypeselectors.nim
index 2a2455adb..eb857271d 100644
--- a/tests/metatype/ttypeselectors.nim
+++ b/tests/metatype/ttypeselectors.nim
@@ -99,3 +99,15 @@ echo sizeof(a)
 echo sizeof(b)
 echo sizeof(c)
 
+# This is the same example but using a proc instead of a macro
+# Instead of type mismatch for macro, proc just failed with internal error: getTypeDescAux(tyNone)
+# https://github.com/nim-lang/Nim/issues/7231
+
+proc getBase2*(bits: static[int]): typedesc =
+  if bits == 128:
+    result = newTree(nnkBracketExpr, ident("MpUintBase"), ident("uint64"))
+  else:
+    result = newTree(nnkBracketExpr, ident("MpUintBase"), ident("uint32"))
+
+type
+  MpUint2*[bits: static[int]] = getbase2(bits)
diff --git a/tests/stdlib/tsugar.nim b/tests/stdlib/tsugar.nim
new file mode 100644
index 000000000..a870bf6fe
--- /dev/null
+++ b/tests/stdlib/tsugar.nim
@@ -0,0 +1,29 @@
+discard """
+  file: "tsugar.nim"
+  output: ""
+"""
+import sugar
+import macros
+
+block distinctBase:
+  block:
+    type
+      Foo[T] = distinct seq[T]
+    var a: Foo[int]
+    doAssert a.type.distinctBase is seq[int]
+
+  block:
+    # simplified from https://github.com/nim-lang/Nim/pull/8531#issuecomment-410436458
+    macro uintImpl(bits: static[int]): untyped =
+      if bits >= 128:
+        let inner = getAST(uintImpl(bits div 2))
+        result = newTree(nnkBracketExpr, ident("UintImpl"), inner)
+      else:
+        result = ident("uint64")
+
+    type
+      BaseUint = UintImpl or SomeUnsignedInt
+      UintImpl[Baseuint] = object
+      Uint[bits: static[int]] = distinct uintImpl(bits)
+
+    doAssert Uint[128].distinctBase is UintImpl[uint64]