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
typeRoom=refobject# reference to an object, useful for big objects or
windows: int# objects inside objects
doors: int=1# Change the default value of a field (since Nim 2.0)House=object
address: string
rooms: seq[Room]
var
defaultHouse =House() # initialize with default values
defaultRoom =newRoom() # create new instance of ref object
sesameHouse =House(address: "123 Sesame St.", rooms: @[defaultRoom])
This piece of code produces an error, more specifically it says you can create a new isntance of ref object using
defaultRoom = new Room() --> but this produces an error
Error: type mismatch
Expression: new Room(doors: 1)
[1] Room(doors: 1): Room
Expected one of (first mismatch at [position]):
[1] proc new(t: typedesc): auto
[1] proc new[T](a: var ref T)
expression 'Room(doors: 1)' is immutable, not 'var'
[1] proc new[T](a: var ref T; finalizer: proc (x: ref T) {.nimcall.})
expression 'Room(doors: 1)' is immutable, not 'var'
Nim Version
2.0.4
Current Output
Error: type mismatch
Expression: new Room(doors: 1)
[1] Room(doors: 1): Room
Expected one of (first mismatch at [position]):
[1] proc new(t: typedesc): auto
[1] proc new[T](a: var ref T)
expression 'Room(doors: 1)' is immutable, not 'var'
[1] proc new[T](a: var ref T; finalizer: proc (x: ref T) {.nimcall.})
expression 'Room(doors: 1)' is immutable, not 'var'
Expected Output
Expected compile to be a success
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered:
Description
This piece of code produces an error, more specifically it says you can create a new isntance of ref object using
defaultRoom = new Room() --> but this produces an error
Nim Version
2.0.4
Current Output
Expected Output
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: