Skip to content

Commit

Permalink
Test union narrowing in generic function
Browse files Browse the repository at this point in the history
  • Loading branch information
kyouko-taiga committed Aug 22, 2024
1 parent 80ed530 commit 29bf165
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Tests/EndToEndTests/TestCases/UnionNarrowing.hylo
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
//- compileAndRun expecting: .success

fun f<T: Regular, U: Regular>(_ u: sink Union<T, U>) -> 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 {
precondition(y.0 == 42)
} else {
fatal_error()
}

precondition(f<Int, Bool>(42 as _))
precondition(f<Int, Int>(42 as _))
precondition(!f<Int, Bool>(true as _))
}

0 comments on commit 29bf165

Please sign in to comment.