mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-29 11:47:56 +00:00
Do not emit object definition it if used only by ref or ptr
This commit is contained in:
12
tests/ccgbugs/mymodule.nim
Normal file
12
tests/ccgbugs/mymodule.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
type
|
||||
MyRefObject* = ref object
|
||||
s: string
|
||||
|
||||
|
||||
proc newMyRefObject*(s: string): MyRefObject =
|
||||
new(result)
|
||||
result.s = s
|
||||
|
||||
proc `$`*(o: MyRefObject): string =
|
||||
o.s
|
||||
|
||||
15
tests/ccgbugs/tforward_decl_only.nim
Normal file
15
tests/ccgbugs/tforward_decl_only.nim
Normal file
@@ -0,0 +1,15 @@
|
||||
discard """
|
||||
ccodecheck: "\\i !@('struct tyObject_MyRefObject'[0-z]+' {')"
|
||||
output: "hello"
|
||||
"""
|
||||
|
||||
# issue #7339
|
||||
# Test that MyRefObject is only forward declared as it used only by reference
|
||||
|
||||
import mymodule
|
||||
type AnotherType = object
|
||||
f: MyRefObject
|
||||
|
||||
let x = AnotherType(f: newMyRefObject("hello"))
|
||||
echo $x.f
|
||||
|
||||
Reference in New Issue
Block a user