Skip to content

Commit e918a76

Browse files
jmgomezAraq
authored andcommitted
fixes compiler crash by preventing exportc on generics (#22731)
Co-authored-by: Andreas Rumpf <[email protected]> (cherry picked from commit fefde3a)
1 parent d56000e commit e918a76

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

compiler/semstmts.nim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,9 +1483,12 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
14831483
# final pass
14841484
if a[2].kind in nkCallKinds:
14851485
incl a[2].flags, nfSem # bug #10548
1486-
if sfExportc in s.flags and s.typ.kind == tyAlias:
1487-
localError(c.config, name.info, "{.exportc.} not allowed for type aliases")
1488-
1486+
if sfExportc in s.flags:
1487+
if s.typ.kind == tyAlias:
1488+
localError(c.config, name.info, "{.exportc.} not allowed for type aliases")
1489+
elif s.typ.kind == tyGenericBody:
1490+
localError(c.config, name.info, "{.exportc.} not allowed for generic types")
1491+
14891492
if tfBorrowDot in s.typ.flags:
14901493
let body = s.typ.skipTypes({tyGenericBody})
14911494
if body.kind != tyDistinct:

tests/types/texportgeneric.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
discard """
2+
errormsg: "{.exportc.} not allowed for generic types"
3+
line: 6
4+
"""
5+
6+
type Struct[T] {.exportc.} = object
7+
a:int
8+
b: T

0 commit comments

Comments
 (0)