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# generation throws an exception when the Q# code uses an invalid identifier #452

Description

When I use an invalid identifier:

@EntryPoint()
function Main() : Unit {
    Foo(); // not defined
}

The Q# compiler rejects it, which is good:

C:/Users/samarsha/Desktop/Project/Program.qs(4,9): error QS5022: No identifier with the name "Foo" exists.

However, C# generation tries to run anyway, which is bad:

  System.Exception: Received InvalidIdentifier
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.StatementBuilder.buildId(Identifier id) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 425
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.StatementBuilder.buildExpression(TypedExpression ex) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 346
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.StatementBuilder.buildApply(ResolvedType returnType, TypedExpression op, TypedExpression args) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 538
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.StatementBuilder.buildExpression(TypedExpression ex) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 384
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.StatementBuilder.OnExpressionStatement(TypedExpression node) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 611
     at Microsoft.Quantum.QsCompiler.Transformations.Core.StatementKindTransformationBase.OnStatementKind(QsStatementKind kind)
     at Microsoft.Quantum.QsCompiler.Transformations.Core.StatementTransformationBase.OnStatement(QsStatement stm)
     at Microsoft.FSharp.Collections.Internal.IEnumerator.map@75.DoMoveNext(b& curr) in E:\A\_work\130\s\src\fsharp\FSharp.Core\seq.fs:line 81 
     at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext() in E:\A\_work\130\s\src\fsharp\FSharp.Core\seq.fs:line 68
     at Microsoft.FSharp.Collections.SeqModule.Iterate[T](FSharpFunc`2 action, IEnumerable`1 source) in E:\A\_work\130\s\src\fsharp\FSharp.Core\seq.fs:line 494
     at Microsoft.Quantum.QsCompiler.Transformations.Core.StatementTransformationBase.OnScope(QsScope scope)
     at Microsoft.Quantum.QsCompiler.Transformations.Core.NamespaceTransformationBase.OnProvidedImplementation(QsTuple`1 argTuple, QsScope body)
     at Microsoft.Quantum.QsCompiler.Transformations.Core.NamespaceTransformationBase.OnSpecializationImplementation(SpecializationImplementation implementation)
     at Microsoft.Quantum.QsCompiler.Transformations.Core.NamespaceTransformationBase.OnSpecializationKind(QsSpecialization spec)
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.buildSpecializationBody(CodegenContext context, QsSpecialization sp) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 952
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.buildSpecialization(CodegenContext context, QsSpecialization sp) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 1004
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.buildOperationClass@1383-2.Invoke(QsSpecialization sp) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 1383
     at Microsoft.FSharp.Collections.Internal.IEnumerator.map@75.DoMoveNext(b& curr) in E:\A\_work\130\s\src\fsharp\FSharp.Core\seq.fs:line 81 
     at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext() in E:\A\_work\130\s\src\fsharp\FSharp.Core\seq.fs:line 68
     at Microsoft.FSharp.Collections.Internal.IEnumerator.choose@171.System-Collections-IEnumerator-MoveNext() in E:\A\_work\130\s\src\fsharp\FSharp.Core\seq.fs:line 178
     at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.buildOperationClass(CodegenContext globalContext, QsCallable op) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 1382
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.buildOne@1517-8.Invoke(QsNamespaceElement _arg1) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 1520
     at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 250
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.buildNamespace(CodegenContext globalContext, NonNullable`1 nsName, FSharpList`1 localElements) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 1521
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.namespaces@1595.Invoke(Tuple`2 tupledArg) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 1595
     at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 250
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.buildSyntaxTree(FSharpList`1 localElements, CodegenContext context) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 1595
EXEC : error QS7109: The compilation step "CsharpGeneration" loaded from "C:/Users/samarsha/.nuget/packages/microsoft.quantum.csharpgeneration/0.11.2006.403/lib/netstandard2.1/Microsoft.Quantum.CsharpGeneration.dll" threw an exception. [C:\Users\samarsha\Desktop\Project\Project.csproj]     at Microsoft.Quantum.QsCompiler.CsharpGeneration.SimulationCode.generate(NonNullable`1 fileName, CodegenContext globalContext) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\SimulationCode.fs:line 1649
     at Microsoft.Quantum.QsCompiler.CsharpGeneration.Emitter.Microsoft-Quantum-QsCompiler-IRewriteStep-Transformation(QsCompilation compilation, QsCompilation& transformed) in D:\a\1\s\submodules\qsharp-runtime\src\Simulation\CsharpGeneration\RewriteStep.fs:line 63
     at Microsoft.Quantum.QsCompiler.RewriteSteps.LoadedStep.Transformation(QsCompilation compilation, QsCompilation& transformed)
     at Microsoft.Quantum.QsCompiler.CompilationLoader.ExecuteRewriteStep(LoadedStep rewriteStep, QsCompilation compilation, QsCompilation& transformed)


  ____________________________________________

  Q# compilation failed: 2 errors, 0 warnings
  1 logged exception

C:\Users\samarsha\.nuget\packages\microsoft.quantum.sdk\0.11.2006.403\Sdk\Sdk.targets(116,5): error MSB3073: Der Befehl "dotnet "C:\Users\samarsha\.nuget\packages\microsoft.quantum.sdk\0.11.2006.403\DefaultItems\../tools/qsc/qsc.dll" build --format MsBuild -v Detailed --response-files 
obj/qsharp/config/qsc.rsp" wurde mit dem Code -3 beendet. [C:\Users\samarsha\Desktop\Project\Project.csproj]

Fehler beim Buildvorgang.

C:/Users/samarsha/Desktop/Project/Program.qs(4,9): error QS5022: No identifier with the name "Foo" exists. [C:\Users\samarsha\Desktop\Project\Project.csproj]
EXEC : error QS7109: The compilation step "CsharpGeneration" loaded from "C:/Users/samarsha/.nuget/packages/microsoft.quantum.csharpgeneration/0.11.2006.403/lib/netstandard2.1/Microsoft.Quantum.CsharpGeneration.dll" threw an exception. [C:\Users\samarsha\Desktop\Project\Project.csproj]C:\Users\samarsha\.nuget\packages\microsoft.quantum.sdk\0.11.2006.403\Sdk\Sdk.targets(116,5): error MSB3073: Der Befehl "dotnet "C:\Users\samarsha\.nuget\packages\microsoft.quantum.sdk\0.11.2006.403\DefaultItems\../tools/qsc/qsc.dll" build --format MsBuild -v Detailed --response-files 
obj/qsharp/config/qsc.rsp" wurde mit dem Code -3 beendet. [C:\Users\samarsha\Desktop\Project\Project.csproj]
    0 Warnung(en)
    3 Fehler

Microsoft.Quantum.Sdk version: 0.11.2006.403

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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