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

array construction of ptr generic object with subtype relation failed #7601

Closed
jangko opened this issue Apr 13, 2018 · 0 comments
Closed

array construction of ptr generic object with subtype relation failed #7601

jangko opened this issue Apr 13, 2018 · 0 comments

Comments

@jangko
Copy link
Contributor

jangko commented Apr 13, 2018

the first example is the working example

type
  Fruit = object of RootObj
    name: string
  Apple = object of Fruit
  Banana = object of Fruit

var
  ir = Fruit(name: "Fruit")
  ia = Apple(name: "apple")
  ib = Banana(name: "banana")

let x = [ia.addr, ib.addr, ir.addr]
for c in x:
  echo cast[int](c)

the second example, differ only in generics, failed to compile

type
  Vehicle[T] = object of RootObj
    tire: T
  Car[T] = object of Vehicle[T]
  Bike[T] = object of Vehicle[T]

var v = Vehicle[int](tire: 3)
var c = Car[int](tire: 4)
var b = Bike[int](tire: 2)

let y = [b.addr, c.addr, v.addr]

this bug was found during #4799 investigation, and needed to fixed before #4799
note: ref object and ref generic is ok, only ptr generic failed

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

No branches or pull requests

1 participant