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

fixes #7002; fixes #17602; disallow using an object allocated on the stack for dynamic dispatch #24071

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Sep 6, 2024

fixes #7002; fixes #17602

It causes undefined behaviors with ORC since objectAssignmentDefect is disabled for ORC

See also #7002 (comment)

Checked with

import strutils

type
    BaseObj = object of RootRef
      id: int
    DerivedObj = object of BaseObj
      name: float
      id2: int

method `$`(bo: BaseObj): string {.base.} =
    echo (bo.id)
    return "Base"

method `$`(dob: DerivedObj): string =
    echo (dob.id, dob.name, dob.id2)
    return "Derived"

type Container = object
    inner: BaseObj

proc foo =
  var
      dob = DerivedObj(id: 12, name: 1.23, id2: 5)
      cont = Container(inner: dob)
      dob2 = BaseObj()

  echo (dob, cont, dob2)

  echo (dob, cont, dob2)

  dob2 = dob

  echo (dob, cont, dob2)

foo()

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