Describe the bug
While writing unit tests for a generic-typed function, I ran into some strange behavior. The function works perfectly when called from the same file, but it seems to return a QVoid when called from the test suite, instead of the expected Bool.
To Reproduce
- Using Visual Studio, create a new Q# Test Project with boilerplate
TestSuiteRunner.cs
- Create a new Q# file in the same namespace containing a generic-typed function that returns a
Bool
- Write a test that calls the function and uses the result in some way.
- Try to build the project.
Example
Target.qs:
namespace Quantum.QSharpTestProject1
{
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
function BuggyReturn<'T> (param: 'T): Bool
{
return true;
}
function AssertBuggyReturn<'T> (param: 'T): Unit
{
if (not BuggyReturn<'T>(param))
{
fail "BuggyReturn returned false";
}
}
}
Tests.qs:
namespace Quantum.QSharpTestProject1
{
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Diagnostics;
function BuggyReturnTest () : Unit
{
AssertBuggyReturn<Int>(0); // This works fine!
if (not BuggyReturn<Int>(0)) // This gives error
{
fail "BuggyReturn returned false";
}
}
}
Note that in the above example, AssertBuggyReturn builds just fine, but BuggyReturnTest does not. It gives the error, Operator '!' cannot be applied to operand of type 'QVoid'.
Expected behavior
The code in AssertBuggyReturn and BuggyReturnTest is exactly the same, and therefore should behave identically. BuggyReturn should always return a Bool and not QVoid.
System information
QDK extension version: 0.9.1909.3002
Visual Studio information:
Microsoft Visual Studio Enterprise 2019
Version 16.3.5
VisualStudio.16.Release/16.3.5+29411.108
Microsoft .NET Framework
Version 4.7.03190
Installed Version: Enterprise
Visual C++ 2019 00433-90101-61314-AA195
Microsoft Visual C++ 2019
...