Skip to content

Bad HIR causes panic: source/compiler/qsc_linter/src/linter.rs:122:14: item id should exist #2593

@minestarks

Description

@minestarks

We get a panic in the language service when the linter runs on the following code, however the bug is not in the linter, but in the HIR generated by the lowerer.

namespace Parent.Foo {
    function Bar() : Unit {}
    export Bar;
}

namespace Baz {
    export Parent as ParentAlias;
}

namespace Main {
    operation Main() : Unit {
        Baz.ParentAlias
    }
}

Playground link: https://microsoft.github.io/qsharp/?code=H4sIAAAAAAAACl2NsQoCMRBE%252B3zFlNrcB2hlCjvBxg8YjhUCuhuSCHJH%252Fl0SgxxutczMm1E%252BJUfOgiuTaJnOZlgdANxfOpdgCs%252B02%252BOAm4aCtXZT3tFSadbRVef0V%252BO5DH5Evr1gHt%252FpEZj%252FoAuDDsqiJPbZJm52u9vOc5k2VV2vrn4ADEjVsMoAAAA%253D&profile=unrestricted

HIR representation for the above. Note how there's a reference to "Item 3" which does not exist in the HIR.

Package:
    entry expression: Expr 18 [0-0] [Type ?]: Call:
        Expr 17 [155-159] [Type ?]: Var: Item 5
        Expr 16 [159-161] [Type Unit]: Unit
    Item 0 [0-69] (Public):
        Namespace ([Ident 5 [10-16] "Parent", Ident 6 [17-20] "Foo"]): Item 1
    Item 1 [27-51] (Public):
        Parent: 0
        Callable 0 [27-51] (function):
            name: Ident 1 [36-39] "Bar"
            input: Pat 2 [39-41] [Type Unit]: Unit
            output: Unit
            functors: empty set
            body: SpecDecl 3 [27-51]: Impl:
                Block 4 [49-51]: <empty>
            adj: <none>
            ctl: <none>
            ctl-adj: <none>
    Item 2 [71-122] (Public):
        Namespace (Ident 7 [81-84] "Baz"): <empty>
    Item 4 [124-202] (Public):
        Namespace (Ident 15 [134-138] "Main"): Item 5
    Item 5 [145-200] (Internal):
        Parent: 4
        Callable 8 [145-200] (operation):
            name: Ident 9 [155-159] "Main"
            input: Pat 10 [159-161] [Type Unit]: Unit
            output: Unit
            functors: empty set
            body: SpecDecl 11 [145-200]: Impl:
                Block 12 [169-200] [Type ?]:
                    Stmt 13 [179-194]: Expr: Expr 14 [179-194] [Type ?]: Var: Item 3
            adj: <none>
            ctl: <none>
            ctl-adj: <none>

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions