From 29bf165494d63f954b8e41c68f866c5a62436f16 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Thu, 22 Aug 2024 13:11:05 +0200 Subject: [PATCH] Test union narrowing in generic function --- Tests/EndToEndTests/TestCases/UnionNarrowing.hylo | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/EndToEndTests/TestCases/UnionNarrowing.hylo b/Tests/EndToEndTests/TestCases/UnionNarrowing.hylo index 24facf842..1d8b280d2 100644 --- a/Tests/EndToEndTests/TestCases/UnionNarrowing.hylo +++ b/Tests/EndToEndTests/TestCases/UnionNarrowing.hylo @@ -1,5 +1,9 @@ //- compileAndRun expecting: .success +fun f(_ u: sink Union) -> Bool { + if let _: T = u { true } else { false } +} + public fun main() { var x: Union<{a: Bool}, {b: Int}> = (b: 42) if let y: {b: _} = x { @@ -7,4 +11,8 @@ public fun main() { } else { fatal_error() } + + precondition(f(42 as _)) + precondition(f(42 as _)) + precondition(!f(true as _)) }