Skip to content

const proc in let array causes invalid codegen #16736

@Anuken

Description

@Anuken

Code

type ProcType = proc()
const something: ProcType = proc() = discard
let arr: array[1, ProcType] = [something]

Current Output

/home/anuke/.cache/nim/bug_d/@mbug.nim.c: In function ‘NimMainModule’:
/home/anuke/.cache/nim/bug_d/@mbug.nim.c:413:99: error: request for member ‘ClE_0’ in something not a structure or union
  413 | lzADdspe4KtMwjNjbL8g[0].ClE_0), colonanonymous___DxAxlW4RjxKP1O7MGX2PnQ.ClE_0);
      |                                                                        ^

/home/anuke/.cache/nim/bug_d/@mbug.nim.c:414:80: error: request for member ‘ClP_0’ in something not a structure or union
  414 | tMwjNjbL8g[0].ClP_0 = colonanonymous___DxAxlW4RjxKP1O7MGX2PnQ.ClP_0;
      |                                                              ^

Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I'/home/anuke/.choosenim/toolchains/nim-#devel/lib' -I/home/anuke -o /home/anuke/.cache/nim/bug_d/@mbug.nim.c.o /home/anuke/.cache/nim/bug_d/@mbug.nim.c' failed with exit code: 1

Expected Output

successful compilation, or at least a nim compilation error

Workarounds

  • Declaring both the proc and the array as const fixes the problem.

Additional Information

  • Occurs in 1.4.2 as well as latest HEAD
  • Occurs with and without --gc:arc
$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-01-16
Copyright (c) 2006-2021 by Andreas Rumpf

44ceefa9fefca58ba32e9638f754d7f4ca8a2b82 (current git head)

Metadata

Metadata

Assignees

No one assigned

    Labels

    const`const x=expr` or `static: stmt`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions