qsharp-compiler icon indicating copy to clipboard operation
qsharp-compiler copied to clipboard

Implementing an existing internal function as public leads to compilation step error

Open msoeken opened this issue 3 years ago • 1 comments

Describe the bug

The following code fails on executing the "Functor Generation" compilation step when running dotnet build once, then succeeds when running dotnet build twice. It should probably fail. The error only happens when the project that contains the code is included as project reference to another project.

To Reproduce

<!-- Library/Library.csproj -->
<Project Sdk="Microsoft.Quantum.Sdk/0.24.208024">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Quantum.Numerics" Version="0.24.208024" />
  </ItemGroup>
</Project>
// Library/Code.qs
namespace Microsoft.Quantum.Convert {
    open Microsoft.Quantum.Arrays;
    open Microsoft.Quantum.Math;

    function BoolArrayAsFixedPoint(integerBits : Int, bits : Bool[]) : Double {
        let numBits = Length(bits);
        let intPart = (Tail(bits) ? -(1 <<< (numBits - 1)) | 0) + BoolArrayAsInt(Most(bits));
        return IntAsDouble(intPart) / PowD(2.0, IntAsDouble(numBits - integerBits));
    }
}
<!-- Test/Test.csproj -->
<Project Sdk="Microsoft.Quantum.Sdk/0.24.208024">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="../Library/Library.csproj" />
    <PackageReference Include="Microsoft.Quantum.Xunit" Version="0.24.208024" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
    <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
  </ItemGroup>

</Project>
// Test/Test.qs
// can be empty

Call dotnet build in the Test directory.

Expected behavior

Should not fail. An internal declaration in a referenced project/package should not interfere with a public declaration in the referencing project. (see comment)

System information

  • Your operating system and .NET Core version : mac OS, .NET 6.0.202

msoeken avatar May 16 '22 20:05 msoeken

The correct behavior would be for it to work fine; An internal declaration in a referenced project/package should not interfere with a public declaration in the referencing project.

bettinaheim avatar May 19 '22 01:05 bettinaheim