Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectAssignmentError for aliased types #10203

Closed
arnetheduck opened this issue Jan 5, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@arnetheduck
Copy link
Contributor

commented Jan 5, 2019

expanded version of typalias:

type
  TMyObj = TYourObj
  TYourObj = object of RootObj
    x, y: int

proc init: TYourObj =
  result.x = 0
  result.y = -1

proc f(x: var TYourObj) =
  discard

var m: TMyObj = init()
f(m)


var a: TYourObj = m
var b: TMyObj = a
[arnetheduck@tempus hello]$ nim c typalias
Hint: used config file '/home/arnetheduck/.choosenim/toolchains/nim-0.19.0/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: typalias [Processing]
CC: typalias
CC: stdlib_system
Hint:  [Link]
Hint: operation successful (12286 lines compiled; 0.321 sec total; 16.395MiB peakmem; Debug Build) [SuccessX]
[arnetheduck@tempus hello]$ ./typalias 
typalias.nim(19)         typalias
assign.nim(124)          genericAssign
assign.nim(97)           genericAssignAux
system.nim(2830)         sysFatal
Error: unhandled exception: invalid object assignment [ObjectAssignmentError]
[arnetheduck@tempus hello]$ nim --version
Nim Compiler Version 0.19.0 [Linux: amd64]
Compiled at 2018-09-26
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: f6c5c636bb1a1f4e1301ae0ba5a8afecef439132
active boot switches: -d:release
@mratsim

This comment has been minimized.

Copy link
Collaborator

commented Jan 11, 2019

I'm pretty sure there was an issue about not allowing stack object slicing or not allowing stack object inheritance if they don't have the exact same size.

@mratsim mratsim added the Inheritance label Jan 11, 2019

@Araq

This comment has been minimized.

Copy link
Member

commented Jan 11, 2019

@mratsim That was fixed.

@Araq Araq added the Showstopper label Jan 11, 2019

@Araq

This comment has been minimized.

Copy link
Member

commented Jan 13, 2019

Workaround:

type
  TYourObj = object of RootObj
    x, y: int
  TMyObj = TYourObj

proc init: TYourObj =
  result.x = 0
  result.y = -1

proc f(x: var TYourObj) =
  discard

var m: TMyObj = init()
f(m)


var a: TYourObj = m
var b: TMyObj = a

Araq added a commit that referenced this issue Jan 13, 2019

Araq added a commit that referenced this issue Jan 13, 2019

@Araq Araq closed this in 05c52ff Jan 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.