Skip to content

C compiler error when using statement list expression with a template #15637

@ghost

Description

Couldn't think of a better title, code speaks for itself.
Found in https://github.com/nocturn9x/japl

Example

proc newString(data: int): int = 
  result = data

template addObject(s: int): untyped =
  discard s
  s

proc slice() =
  let obj = addObject(newString((var intval = 5; intval)))

slice()

Current Output

/home/dian/.cache/nim/a_d/@ma.nim.c: In functionslice__GUeAIxBAJ79bdeFn6EpeyzA’:
/home/dian/.cache/nim/a_d/@ma.nim.c:94:5: error: redeclaration ofintvalwith no linkage
   94 |  NI intval;
      |     ^~~~~~
/home/dian/.cache/nim/a_d/@ma.nim.c:92:5: note: previous declaration ofintvalwas here
   92 |  NI intval;
      |     ^~~~~~

Expected Output

Successful compilation?

Possible Solution

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2020-10-18
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 82adefa9d10485478456ff75a700d982471708d2
active boot switches: -d:release -d:danger

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions