diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2018-08-10 00:20:14 -0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-10 09:20:14 +0200 |
commit | 43f634db8dfac4fb13c8454958d35e776410dac1 (patch) | |
tree | 9cbbddca55b70e5e85daac9bc9edf9381f46c01a /tests | |
parent | 730ce53b71a207edf93abe09c14c150b9c360028 (diff) | |
download | Nim-43f634db8dfac4fb13c8454958d35e776410dac1.tar.gz |
fixes #8519; implements T.distinctBase to reverse T = distinct A (#8531)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdlib/tsugar.nim | 29 |
1 files changed, 29 insertions, 0 deletions
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] |