Codegen: use type forward declarations more aggresively. Fixes #7339 (#7340)

Do not emit object definition it if used only by ref or ptr
This commit is contained in:
cooldome
2018-03-16 15:21:03 +00:00
committed by Andreas Rumpf
parent a9f21cffdf
commit 70b28a39fe
4 changed files with 32 additions and 1 deletions

View 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

View 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