You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nil without a type and no way to infer the type is typed to typeof(nil), so simply doing
type
A =refobject
impl: pointer
i: int
B =refobject
impl: pointer
j: int#proc t(x: A = nil) = # worksproct(x: A | B =A(nil)) =echo(if x ==nil: "nil"else: $(cast[int](x.impl)))
procmain=var h: A
t() # Error: cannot instantiate: 'T't(h) # workst(x =B(nil)) # Error: undeclared field: 'impl'main()
Solves the latter issue.
What you may want is:
proct(x: A | B) =echo(if x ==nil: "nil"else: $(cast[int](x.impl)))
proct(x: typedesc[A | B]) =t(default(x))
# The folllowing can be used for the `nil` case.t(A)
t(B)
The text was updated successfully, but these errors were encountered: