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

ordinary object slicing in varargs generate bad codegen #7956

Open
jangko opened this issue Jun 5, 2018 · 2 comments
Open

ordinary object slicing in varargs generate bad codegen #7956

jangko opened this issue Jun 5, 2018 · 2 comments

Comments

@jangko
Copy link
Contributor

jangko commented Jun 5, 2018

this is an offshoot from #4799

type
  Vehicle = object of RootObj
    tire: int
  Car = object of Vehicle
  Bike = object of Vehicle

proc testVehicle(x: varargs[Vehicle]): string =
  result = ""
  for c in x:
    result.add $c.tire

var v = Vehicle(tire: 3)
var c = Car(tire: 4)
var b = Bike(tire: 2)
echo testVehicle b, c, v

if compiled, it should success, but will fail at runtime with ObjectAssignmentError
see #7712 and #7637

currently, it generate bad codegen

@Araq
Copy link
Member

Araq commented Jun 6, 2018

This is not a bug, this works as expected. Object slicing does not depend on the actual existence of additional fields.

@jangko
Copy link
Contributor Author

jangko commented Jun 6, 2018

sorry for my broken English, I should say: after #4799 fixed, this will become codegen bug.
the situation before #4799 fixed is the code cannot be compiled at all.
the slicing problem is a probability issue, best to anticipate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants