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.

C# code generation generates invalid properties for UDTs with tuple-valued named items #40

@cgranade

Description

@cgranade

Describe the bug

When defining a UDT with a named item whose type is a non-singleton tuple, the C# code generation step produces invalid properties that then fail to compile when running dotnet build.

To Reproduce

namespace runtime_bug {
    open Microsoft.Quantum.Arrays;
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Intrinsic;

    newtype GeneratorIndex = (IndexData: (Int[], Double[]), Subsystems: Int[]);

    function Example() : GeneratorIndex[] {
        return Mapped(
            GeneratorIndex(_, [0, 1, 2]),
            [
                ([0], [0.0]),
                ([1, 1], [1.1, 1.1]),
                ([2, 2, 2], [2.2, 2.2, 2.2])
            ]
        );
    }

    function Boom() : Int {
        let foos = Example();
        Message($"{foos}");
        return (Fst(foos[0]::IndexData))[0];
    }
}

Expected behavior

Boom should return 0.

Actual behavior

obj\qsharp\src\Operations.g.cs(27,62): error CS0029: Cannot implicitly convert type 'Microsoft.Quantum.Simulation.Core.IQArray<long>' to '(Microsoft.Quantum.Simulation.Core.IQArray<long>, Microsoft.Quantum.Simulation.Core.IQArray<double>)' [C:\Users\chgranad.REDMOND\tmp\runtime-bug\runtime-bug.csproj]
obj\qsharp\src\Operations.g.cs(28,45): error CS0266: Cannot implicitly convert typ  'Microsoft.Quantum.Simulation.Core.IQArray<double>' to 'Microsoft.Quantum.Simulation.Core.IQArray<long>'. An explicit conversion exists (are you missing a cast?) [C:\Users\chgranad.REDMOND\tmp\runtime-bug\runtime-bug.csproj]

The generated code referred to by the above error:

public (IQArray<Int64>,IQArray<Double>) IndexData => Data.Item1.Item1;
public IQArray<Int64> Subsystems => Data.Item1.Item2;
public (IQArray<Int64>,IQArray<Double>) Item1 => Data.Item1;
public IQArray<Int64> Item2 => Data.Item2;

System information

  • OS: Windows 10

  • .NET Core Version: 3.0.100-preview8-013656

  <ItemGroup>
    <PackageReference Include="Microsoft.Quantum.Standard" Version="0.8.1907.2504" />
    <PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.8.1907.2504" />
  </ItemGroup>

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions