Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/QsCompiler/SyntaxProcessor/ContextVerification.fs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ let rec internal freeVariables e =
| CONDITIONAL (e1, e2, e3) -> freeVariables e1 |> merge (freeVariables e2) |> merge (freeVariables e3)
| ValueTuple es
| StringLiteral (_, es)
| ValueArray es -> es |> Seq.map freeVariables |> Seq.reduce merge
| ValueArray es -> es |> Seq.map freeVariables |> Seq.fold merge Map.empty
| Lambda lambda ->
let bindings = unqualifiedSymbols lambda.Param
freeVariables lambda.Body |> Map.filter (fun name _ -> Set.contains name bindings |> not)
8 changes: 8 additions & 0 deletions src/QsCompiler/Tests.Compiler/TestCases/TypeChecking.qs
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,14 @@ namespace Microsoft.Quantum.Testing.TypeChecking {
return () -> 0;
}

function Lambda15<'a>() : 'a -> String {
return x -> "foo";
}

function Lambda16<'a>() : 'a -> 'a[] {
return x -> [];
}

function LambdaInvalid1() : Qubit => Unit is Adj {
return q => Operation(q);
}
Expand Down
2 changes: 1 addition & 1 deletion src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module TypeCheckingTests =

[<Fact>]
let ``Supports lambda expressions`` () =
allValid "Lambda" 14
allValid "Lambda" 16
expect "LambdaInvalid1" [ Error ErrorCode.TypeMismatchInReturn ]
expect "LambdaInvalid2" [ Error ErrorCode.TypeMismatchInReturn ]
expect "LambdaInvalid3" (Error ErrorCode.InfiniteType |> List.replicate 2)
Expand Down