mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-27 09:43:58 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user