summary refs log tree commit diff stats
path: root/tests/implicit/timplictderef.nim
blob: fcb647217ca5ea22a5e32f4a80099bed13c1876f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
discard """
  output: '''2
88'''
"""

type
  TValue* {.pure, final.} = object of RootObj
    a: int
  PValue = ref TValue
  PPValue = ptr PValue


var x: PValue
new x
var sp: PPValue = addr x

sp.a = 2
if sp.a == 2: echo 2  # with sp[].a the error is gone

# Test the new auto-deref a little

{.experimental.}

proc p(x: var int; y: int) = x += y

block:
  var x: ref int
  new(x)

  x.p(44)

  var indirect = p
  x.indirect(44)

  echo x[]