From a480cbddccd499c826438a120c567bbbdee7211a Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Fri, 30 Oct 2020 16:58:55 +0800 Subject: [PATCH] closes #7658 (#15784) * fix #7658 * more (cherry picked from commit 17f08b2939db224d533db846fc3fa8ab91cc9755) --- compiler/pragmas.nim | 9 ++++++--- tests/js/tunion.nim | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 tests/js/tunion.nim diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 4d5240e3c2..7dbcfd6ffa 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -1110,9 +1110,12 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, else: sym.typ.kind = tyUncheckedArray of wUnion: - noVal(c, it) - if sym.typ == nil: invalidPragma(c, it) - else: incl(sym.typ.flags, tfUnion) + if c.config.backend == backendJs: + localError(c.config, it.info, "`{.union.}` is not implemented for js backend.") + else: + noVal(c, it) + if sym.typ == nil: invalidPragma(c, it) + else: incl(sym.typ.flags, tfUnion) of wRequiresInit: noVal(c, it) if sym.kind == skField: diff --git a/tests/js/tunion.nim b/tests/js/tunion.nim new file mode 100644 index 0000000000..e185495adf --- /dev/null +++ b/tests/js/tunion.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "`{.union.}` is not implemented for js backend." +""" + +type Foo {.union.} = object + as_bytes: array[8, int8] + data: int64