mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 04:44:20 +00:00
the is operator now works with type classes and type variables
bugfixes: the DLL tests were failing on Mac OS X, due to an incorrect DynlibFormat
This commit is contained in:
42
tests/compile/tisop.nim
Normal file
42
tests/compile/tisop.nim
Normal file
@@ -0,0 +1,42 @@
|
||||
import typetraits
|
||||
|
||||
type
|
||||
TRecord = (tuple) or (object)
|
||||
|
||||
TFoo[T, U] = object
|
||||
x: int
|
||||
|
||||
when T is string:
|
||||
y: float
|
||||
else:
|
||||
y: string
|
||||
|
||||
when U is TRecord:
|
||||
z: float
|
||||
|
||||
E = enum A, B, C
|
||||
|
||||
macro m(t: typedesc): typedesc =
|
||||
if t is enum:
|
||||
result = string
|
||||
else:
|
||||
result = int
|
||||
|
||||
var f: TFoo[int, int]
|
||||
static: assert(f.y.type.name == "string")
|
||||
|
||||
when compiles(f.z):
|
||||
{.error: "Foo should not have a `z` field".}
|
||||
|
||||
proc p(a, b) =
|
||||
when a.type is int:
|
||||
static: assert false
|
||||
|
||||
var f: TFoo[m(a.type), b.type]
|
||||
static:
|
||||
assert f.x.type.name == "int"
|
||||
assert f.y.type.name == "float"
|
||||
assert f.z.type.name == "float"
|
||||
|
||||
p(A, f)
|
||||
|
||||
@@ -2,8 +2,8 @@ type
|
||||
TFoo[T] = object
|
||||
val: T
|
||||
|
||||
T1 = distinct expr
|
||||
T2 = distinct expr
|
||||
T1 = expr
|
||||
T2 = expr
|
||||
|
||||
proc takesExpr(x, y) =
|
||||
echo x, y
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
discard """
|
||||
file: "tcaseexpr1.nim"
|
||||
|
||||
line: 23
|
||||
errormsg: "not all cases are covered"
|
||||
|
||||
line: 29
|
||||
errormsg: "type mismatch: got (string) but expected 'int'"
|
||||
|
||||
line: 23
|
||||
errormsg: "not all cases are covered"
|
||||
"""
|
||||
|
||||
type
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
file: "system.nim"
|
||||
line: 643
|
||||
line: 649
|
||||
errormsg: "type mismatch"
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user