microsoft / qsharp-runtime

Runtime components for Q#
https://docs.microsoft.com/quantum
MIT License
285 stars 93 forks source link

Unsupported Recursive Behavior in Simulator Test Circuit #343

Closed ScottCarda-MS closed 4 years ago

ScottCarda-MS commented 4 years ago

There is a circuit defined in the simulation tests here: https://github.com/microsoft/qsharp-runtime/blob/master/src/Simulation/Simulators.Tests/Circuits/Recursion.qs#L42

function GenRecursionPartial<'T> (x : 'T, cnt : Int) : 'T {        
    if (cnt == 0) {
        return x;
    }
    else {
        let fct = GenRecursionPartial(_, cnt - 1);
        return fct(x);
    }
}

This should not be allowed as fct is capturing an unresolved generic reference to GenRecursionPartial. The reason why this is not throwing the appropriate error is a compiler bug and can be found here: https://github.com/microsoft/qsharp-compiler/issues/574.

This test case should be removed, as it is not a supported scenario.

bamarsha commented 4 years ago

If the compiler behavior is changed according to microsoft/qsharp-compiler#574, instead of removing the test case, would another option be to change GenRecursionPartial(_, cnt - 1) to GenRecursionPartial<'T>(_, cnt - 1) to explicitly resolve the type variable?

ScottCarda-MS commented 4 years ago

Hmm, yes I think that would solve the issue well. I had thought at first that the purpose of these tests was to test the type argument inference, but now I don't think that's the case, so the test would still be useful to its purpose if given the type argument explicitly.