Dotborrow now works with generic distincts (#18848)
This commit is contained in:
parent
ef390e6a68
commit
172253cb55
4 changed files with 37 additions and 7 deletions
|
|
@ -33,3 +33,23 @@ let b = Radians(1.0)
|
|||
a -= b
|
||||
|
||||
echo a.float64
|
||||
|
||||
block: #14449
|
||||
type
|
||||
Foo[T] = object
|
||||
foo: T
|
||||
|
||||
Bar[T] {.borrow:`.`.} = distinct Foo[T]
|
||||
SomeThing {.borrow:`.`.} = distinct Foo[float]
|
||||
OtherThing {.borrow:`.`.} = distinct SomeThing
|
||||
|
||||
var
|
||||
a: Bar[int]
|
||||
b: SomeThing
|
||||
c: OtherThing
|
||||
a.foo = 300
|
||||
b.foo = 400
|
||||
c.foo = 42
|
||||
assert a.foo == 300
|
||||
assert b.foo == 400d
|
||||
assert c.foo == 42d
|
||||
|
|
@ -1,16 +1,25 @@
|
|||
discard """
|
||||
errormsg: "no symbol to borrow from found"
|
||||
line: 11
|
||||
cmd: "nim check --hints:off --warnings:off $file"
|
||||
action: "reject"
|
||||
nimout:'''
|
||||
tinvalidborrow.nim(18, 3) Error: only a 'distinct' type can borrow `.`
|
||||
tinvalidborrow.nim(19, 3) Error: only a 'distinct' type can borrow `.`
|
||||
tinvalidborrow.nim(20, 1) Error: no symbol to borrow from found
|
||||
'''
|
||||
"""
|
||||
|
||||
# bug #516
|
||||
|
||||
type
|
||||
TAtom = culong
|
||||
|
||||
Test {.borrow:`.`.} = distinct int
|
||||
Foo[T] = object
|
||||
a: int
|
||||
Bar[T] {.borrow:`.`.} = Foo[T]
|
||||
OtherFoo {.borrow:`.`.} = Foo[int]
|
||||
proc `==`*(a, b: TAtom): bool {.borrow.}
|
||||
|
||||
var
|
||||
d, e: TAtom
|
||||
|
||||
echo( $(d == e) )
|
||||
discard( $(d == e) )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue