Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Unexpected behavior when defining variables with the same name in enclosing scopes #1459

Open
@tcNickolas

Description

@tcNickolas

Describe the bug

I'm observing several odd behaviors, I'm not sure which of them are bugs and which are expected, so I'll report them all at once without unentangling them.

  1. The following code throws an error CS0136 A local or parameter named 'angle' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter, even though the angle variable in the outer scope is defined after the loop, so no shadowing occurs.
    operation Tmp() : Unit {
        for i in 0 .. 1 {
            let angle = i * 2;
        }
        let angle = 0;
    }

I'm also not sure how to interpret a local or parameter phrase - is it something like "a local variable or parameter"?

  1. With an extra conjugation in place, the same code passes compilation, though if the variable angle in the loop was shadowing the variable outside of it, it is still doing it with an extra block inside.
    operation Tmp() : Unit {
        for i in 0 .. 1 {
             within {
                let angle = i * 2;
             } apply {
                let a = 1;
             }
        }
        let angle = 0;
    }

Additionally, it gives a warning The variable '__qsVar1__a__' is assigned but its value is never used, which looks like something from QIR, since the user-facing variable name is a. The unused variable warning for angle looks as expected.

System information

  • QDK 0.24.210930

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions