-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
The following code compiles:
type
MyObject = object
x: int
proc doSomething(obj: var MyObject) =
obj.x = 123
proc doSomething(obj: ref MyObject) =
obj.x = 123
let refObj = MyObject.new
doSomething(refObj)
echo $refObj.x
var varObj = MyObject(x: 0)
doSomething(varObj)
echo $varObj.xwhile the following code does not:
type
MyObject = object
x: int
proc doSomething(obj: var MyObject | ref MyObject) =
obj.x = 123
let refObj = MyObject.new
doSomething(refObj)
echo $refObj.x
var varObj = MyObject(x: 0)
doSomething(varObj)
echo $varObj.xinstead giving the following compilation error:
test.nim(13, 12) template/generic instantiation from here
test.nim(6, 6) Error: 'obj.x' cannot be assigned to
Metadata
Metadata
Assignees
Labels
No labels