microsoft / qsharp-runtime

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

Constructor on type not found #102

Open sam-jaques opened 4 years ago

sam-jaques commented 4 years ago

Describe the bug Constructing a function (Int -> 'T) for a parameterized type 'T and passing it to another operation causes an issue when the function is called.

To Reproduce Steps to reproduce the behavior:

Call ConstructFailure() in the following code:

open Microsoft.Quantum.Arrays();
    operation ConstructFailure() : Unit {
        let table = [1,2,3,4];
        TableFailure(table);
    }

    operation TableFailure<'T>(table : 'T[]) : Unit {
        let lFunction = LookupFunction(table);
        let x = lFunction(0);
        Message("Has not failed");
        LookupFailure(LookupFunction(table));
    }

    operation LookupFailure<'T> (lookup : (Int -> 'T)) : Unit {
        let x =  lookup(0);
        Message("Still has not failed");
    }

Expected behavior lookup should be callable from within LookupFailure. Instead, it does not reach the second Message line before giving the error:

Unhandled Exception: System.AggregateException: One or more errors occurred. (Constructor on type 'Microsoft.Quantum.Simulation.Core.IQArray1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' not found.) ---> System.MissingMethodException: Constructor on type 'Microsoft.Quantum.Simulation.Core.IQArray1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' not found. at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at Microsoft.Quantum.Simulation.Core.PartialMapper.CastTuple(Type targetType, Object value) at Microsoft.Quantum.Simulation.Core.PartialMapper.CastTuple(Type targetType, Object value) at Microsoft.Quantum.Simulation.Core.PartialMapper.<>cDisplayClass9_02.<Create>b__0(P argTuple) at Microsoft.Quantum.Simulation.Core.FunctionPartial3.b16_0(P a) at Microsoft.Quantum.Simulation.Core.Function2.Apply[GenO](Object args) at Microsoft.Quantum.Simulation.Core.GenericCallable.Apply[O](Object args) at Microsoft.Quantum.Crypto.Canon.LookupFailure1.b__10_0(ICallable in)

Screenshots If applicable, add screenshots to help explain your problem.

System information

bettinaheim commented 4 years ago

@sam-jaques Thanks for reporting! I'll see that I can look into it.

bettinaheim commented 4 years ago

This may be the same issue as https://github.com/microsoft/qsharp-runtime/issues/48.