summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJuan M Gómez <info@jmgomez.me>2023-09-20 07:19:29 +0100
committerGitHub <noreply@github.com>2023-09-20 08:19:29 +0200
commitfefde3a735c3bc931a4d3289e43f3b95f65e1256 (patch)
treec48663c7cf28ea53fcd0fc2f2962f6bffa8f77c7
parent5568ba0d9f39469891b5e4625ad39ebcfa5e1ee3 (diff)
downloadNim-fefde3a735c3bc931a4d3289e43f3b95f65e1256.tar.gz
fixes compiler crash by preventing exportc on generics (#22731)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r--compiler/semstmts.nim9
-rw-r--r--tests/types/texportgeneric.nim8
2 files changed, 14 insertions, 3 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 75b575fd9..2df1c42b3 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -1486,9 +1486,12 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
       # final pass
       if a[2].kind in nkCallKinds:
         incl a[2].flags, nfSem # bug #10548
-    if sfExportc in s.flags and s.typ.kind == tyAlias:
-      localError(c.config, name.info, "{.exportc.} not allowed for type aliases")
-
+    if sfExportc in s.flags:
+      if s.typ.kind == tyAlias:
+        localError(c.config, name.info, "{.exportc.} not allowed for type aliases")
+      elif s.typ.kind == tyGenericBody:
+        localError(c.config, name.info, "{.exportc.} not allowed for generic types")
+    
     if tfBorrowDot in s.typ.flags:
       let body = s.typ.skipTypes({tyGenericBody})
       if body.kind != tyDistinct:
diff --git a/tests/types/texportgeneric.nim b/tests/types/texportgeneric.nim
new file mode 100644
index 000000000..9e6be2bb6
--- /dev/null
+++ b/tests/types/texportgeneric.nim
@@ -0,0 +1,8 @@
+discard """
+  errormsg: "{.exportc.} not allowed for generic types"
+  line: 6
+"""
+
+type Struct[T] {.exportc.} = object
+  a:int
+  b: T
\ No newline at end of file