diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 75f3375..619f14e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,9 @@ +------------------------------------------------------------------------------ + qSharp 2.0.7 [TBA] +------------------------------------------------------------------------------ + + - Fix: validate lambda expression upon construction + ------------------------------------------------------------------------------ qSharp 2.0.6 [2014.09.11] ------------------------------------------------------------------------------ diff --git a/qSharp/src/QLambda.cs b/qSharp/src/QLambda.cs index 589bd5c..35ef3db 100644 --- a/qSharp/src/QLambda.cs +++ b/qSharp/src/QLambda.cs @@ -28,6 +28,7 @@ public sealed class QLambda /// /// Creates new QLambda instance with given body and parameters. + /// Note that expression is trimmed and required to be enclosed in { and } brackets. /// public QLambda(string expression, Array parameters = null) { @@ -35,6 +36,18 @@ public QLambda(string expression, Array parameters = null) { throw new ArgumentException("Lambda expression cannot be null"); } + expression = expression.Trim(); + + if (expression.Length == 0) + { + throw new ArgumentException("Lambda expression cannot be empty"); + } + + if (expression[0] != '{' || expression[expression.Length - 1] != '}') + { + throw new ArgumentException("Lambda expression is expected to be enclosed in {} brackets"); + } + this.expression = expression; this.parameters = parameters; }