deprecate NewFinalize with the ref T finalizer (#24354)

pre-existing issues:

```nim
block:
  type
    FooObj = object
      data: int
    Foo = ref ref FooObj


  proc delete(self: Foo) =
    echo self.data

  var s: Foo
  new(s, delete)
```
it crashed with arc/orc in 1.6.x and 2.x.x

```nim
block:
  type
    Foo = ref int


  proc delete(self: Foo) =
    echo self[]

  var s: Foo
  new(s, delete)
```

The simple fix is to add a type restriction for the type `T` for arc/orc
versions
```nim
  proc new*[T: object](a: var ref T, finalizer: proc (x: T) {.nimcall.})
```
This commit is contained in:
ringabout
2024-10-26 04:35:26 +08:00
committed by GitHub
parent d303c289fa
commit 2af602a5c8
4 changed files with 86 additions and 39 deletions

View File

@@ -834,3 +834,30 @@ block: # bug #24141
doAssert abc == "fbc"
main()
block:
type
FooObj = object
data: int
Foo = ref FooObj
proc delete(self: FooObj) =
discard
var s = Foo()
new(s, delete)
block:
type
FooObj = object
data: int
i1, i2, i3, i4: float
Foo = ref FooObj
proc delete(self: FooObj) =
discard
var s = Foo()
new(s, delete)