diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index e0fb9b7894ca..39e85eb6a965 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1719,6 +1719,17 @@ proc typeSectionFinalPass(c: PContext, n: PNode) = # check the style here after the pragmas have been processed: styleCheckDef(c, s) # compute the type's size and check for illegal recursions: + if a[0].kind == nkPragmaExpr: + let pragmas = a[0][1] + for i in 0 ..< pragmas.len: + if pragmas[i].kind == nkExprColonExpr and + pragmas[i][0].kind == nkIdent and + whichKeyword(pragmas[i][0].ident) == wSize: + if s.typ.kind != tyEnum and sfImportc notin s.flags: + # EventType* {.size: sizeof(uint32).} = enum + # AtomicFlag* {.importc: "atomic_flag", header: "", size: 1.} = object + localError(c.config, pragmas[i].info, "size pragma only allowed for enum types and imported types") + if a[1].kind == nkEmpty: var x = a[2] if x.kind in nkCallKinds and nfSem in x.flags: