Skip to content

Commit 46bfb59

Browse files
cooldomeAraq
authored andcommitted
fixes #13281 (#13282)
* fixes ##13281 * add comment to test
1 parent c841865 commit 46bfb59

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

compiler/semtypes.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
698698
father.add a
699699

700700
proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
701-
father: PNode, rectype: PType, hasCaseFields = false) =
701+
father: PNode, rectype: PType, hasCaseFields: bool) =
702702
if n == nil: return
703703
case n.kind
704704
of nkRecWhen:
@@ -727,12 +727,12 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
727727
assign(newCheck, check)
728728
var newPos = pos
729729
var newf = newNodeI(nkRecList, n.info)
730-
semRecordNodeAux(c, it[idx], newCheck, newPos, newf, rectype)
730+
semRecordNodeAux(c, it[idx], newCheck, newPos, newf, rectype, hasCaseFields)
731731
it[idx] = if newf.len == 1: newf[0] else: newf
732732
if c.inGenericContext > 0:
733733
father.add n
734734
elif branch != nil:
735-
semRecordNodeAux(c, branch, check, pos, father, rectype)
735+
semRecordNodeAux(c, branch, check, pos, father, rectype, hasCaseFields)
736736
of nkRecCase:
737737
semRecordCase(c, n, check, pos, father, rectype)
738738
of nkNilLit:
@@ -741,7 +741,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
741741
# attempt to keep the nesting at a sane level:
742742
var a = if father.kind == nkRecList: father else: copyNode(n)
743743
for i in 0..<n.len:
744-
semRecordNodeAux(c, n[i], check, pos, a, rectype)
744+
semRecordNodeAux(c, n[i], check, pos, a, rectype, hasCaseFields)
745745
if a != father: father.add a
746746
of nkIdentDefs:
747747
checkMinSonsLen(n, 3, c.config)

tests/ccgbugs/tcgbug.nim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ discard """
22
output: '''
33
success
44
M1 M2
5+
ok
56
'''
67
"""
78

@@ -39,7 +40,8 @@ type
3940
var k = PFuture[void]()
4041

4142

42-
##bug #9297
43+
##bug #9297 and #13281
44+
4345
import strutils
4446

4547
type
@@ -58,6 +60,14 @@ type
5860
of M2: b:float
5961
of M3: c:cstring
6062

63+
Helper* {.exportc: "PublicHelper".} = object
64+
case isKind: bool
65+
of true:
66+
formatted: string
67+
of false:
68+
parsed1: string
69+
parsed2: string
70+
6171
proc newMyObject(kind: MyKind, val: string): MyObject =
6272
result = MyObject(kind: kind)
6373

@@ -75,3 +85,9 @@ proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
7585

7686

7787
echo newMyObject(M1, "2").kind, " ", newMyObjectRef(M2, "3").kind
88+
89+
90+
proc test(c: Helper): string =
91+
c.formatted
92+
93+
echo test(Helper(isKind: true, formatted: "ok"))

0 commit comments

Comments
 (0)