mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-24 16:25:25 +00:00
This commit is contained in:
committed by
Andreas Rumpf
parent
730ce53b71
commit
43f634db8d
29
tests/stdlib/tsugar.nim
Normal file
29
tests/stdlib/tsugar.nim
Normal file
@@ -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]
|
||||
Reference in New Issue
Block a user