tobj_asgn_dont_slice.nim 417 B

12345678910111213141516171819202122232425
  1. discard """
  2. outputsub: '''ObjectAssignmentDefect'''
  3. exitcode: "1"
  4. """
  5. # bug #7637
  6. type
  7. Fruit = object of RootObj
  8. name*: string
  9. Apple = object of Fruit
  10. Pear = object of Fruit
  11. method eat(f: Fruit) {.base.} =
  12. raise newException(Exception, "PURE VIRTUAL CALL")
  13. method eat(f: Apple) =
  14. echo "fruity"
  15. method eat(f: Pear) =
  16. echo "juicy"
  17. let basket = [Apple(name:"a"), Pear(name:"b")]
  18. eat(basket[0])