Skip to content

newruntime and computed goto: variables inside the loop are in generated code uninitialised #12785

@RSDuck

Description

@RSDuck

Here's an example:

Example

proc test(a: range[0..1]) = while true: {.computedGoto.} let b = int(a) * 2 case a  of 0: echo b break  of 1: echo b break test(1)

The reason for this is that in C code b is always redefined, for each individual case. This is the reason the value assigned to b during the previous iteration is lost.

Current Output

This can vary based on what's still in register/memory

42 

Expected Output

2 

Additional Information

Nim Compiler Version 1.1.1 [Windows: amd64] Compiled at 2019-11-29 Copyright (c) 2006-2019 by Andreas Rumpf git hash: c5c6bae2a42734df2ba5fdb7cd8cf327d4e7005f active boot switches: -d:release 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions