Specifically, my argument is this:
func foo(n: Int) -> Int {
return n / 0 // Should fail to compile, will always trap.
}
func bar(n: Int) -> Int {
if n % 2 == 0 {
return n / 0 // Should fail to compile, will trap for all n that can enter this branch
} else {
return n / 2
}
}
func baz(n: Int) -> Int {
if n % 2 == 0 {
return n + 1 / n // Must compile, will only trap for some inputs that enter this branch
} else {
return n / 2
}
}
func boz(n: Int) -> Int {
if n != 0 {
return 5 / n // Must compile, will never trap for any n that can enter this branch
} else {
return 5
}
}
baz(0) // Iff baz's definition is available, should fail to compile as this will unconditionally trap.
boz(0) // Must compile, an example of the bug being discussed here