Skip to content

Commit

Permalink
Fix #5: validate lambda expression upon construction
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejlach committed Sep 24, 2014
1 parent a589c07 commit 6be5d4a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------------------------------
qSharp 2.0.7 [TBA]
------------------------------------------------------------------------------

- Fix: validate lambda expression upon construction

------------------------------------------------------------------------------
qSharp 2.0.6 [2014.09.11]
------------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions qSharp/src/QLambda.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@ public sealed class QLambda

/// <summary>
/// Creates new QLambda instance with given body and parameters.
/// Note that expression is trimmed and required to be enclosed in { and } brackets.
/// </summary>
public QLambda(string expression, Array parameters = null)
{
if (expression == 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;
}
Expand Down

0 comments on commit 6be5d4a

Please sign in to comment.