This code compiles with default gc and with --gc:arc:
type
Language* = ref object
impl*: pointer
proc gBoxedFreePangoLanguage*(self: Language) =
discard
proc languageFromString*(): Language =
var l: Language
new(result)
new(result, gBoxedFreePangoLanguage)
$ nim c --gc:arc t6.nim
Hint: 20040 LOC; 0.129 sec; 19.73MiB peakmem; Debug build; proj: /tmp/hhh/t6.nim; out: /tmp/hhh/t6 [SuccessX]
But this code does only compile with default gc:
type
Language* = ref object
impl*: pointer
proc gBoxedFreePangoLanguage*(self: Language) =
discard
proc languageFromString*(): Language =
new(result)
proc getSampleLanguage*(): Language =
new(result, gBoxedFreePangoLanguage)
$ nim c t4.nim
Hint: used config file '/home/stefan/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/stefan/Nim/config/config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: t4 [Processing]
Hint: gcc -o /tmp/hhh/t4 /tmp/stefan/.cache/nim/t4_d/stdlib_system.nim.c.o /tmp/stefan/.cache/nim/t4_d/@mt4.nim.c.o -ldl [Link]
Hint: 22196 LOC; 0.153 sec; 19.762MiB peakmem; Debug build; proj: /tmp/hhh/t4.nim; out: /tmp/hhh/t4 [SuccessX]
$ nim c --gc:arc t4.nim
Hint: used config file '/home/stefan/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/stefan/Nim/config/config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: t4 [Processing]
/tmp/hhh/t4.nim(12, 6) Error: cannot bind another '=destroy' to: Language:ObjectType; previous declaration was constructed here implicitly: /tmp/hhh/t4.nim(9, 6)
For me that was and still is confusing, I would prefer the last not compiling case, because in the other cases the finalizer can be called unintentionally.
I know that :-)
The point is that only the bottom most code above compiling with --gc:arc give us the desired compile-time error. The topmost code compiles always without error, the bottom most code compiles with default gc.
Well, it is indeed good enough, our actual code should most of the time look like the bottom most code, and we can compile always with --gc:arc to check for errors even when we intent to use another GC.