A language has distinct Int and Bool types and no implicit conversions. A conditional requires a Bool condition and identically typed branches. Its checker checks both branches using their types and performs no additional value analysis. At runtime, the conditional evaluates only the chosen branch.
The function divide: (Int, Int) -> Int raises a runtime error whenever its second argument is zero. Integer literals have type Int, and true and false have type Bool.
fun safe(flag: Bool): Int = if flag then 8 else divide(23, 0)
Select every true statement about the definition and its calls.
The definition passes static type checking because its condition is Bool and both branches have type Int.
The call safe(false) completes normally because a successfully checked function body guarantees that every runtime operation succeeds.
The definition fails static type checking because its unchosen branch could encounter a division-by-zero runtime error.
The call safe(true) returns 8 because the conditional selects its first branch without evaluating divide(23, 0).
Unlock full course notes by signing up
Following a nested argument failure
An order-processing program uses the explicitly declared function signatures below. Integer literals have type Int, function arguments must match parameter types exactly, and there are no implicit conversions.
Check this entire expression:
Enter its type, Int or Bool, if every required check succeeds. Otherwise enter rejected, even if the outer function has a declared result type.
Recovering omitted function annotations
A developer leaves the parameter and result annotations out of three functions. Infer their types using only these language rules:
Integer literals have type Int, Boolean literals have type Bool, and quoted text has type String.
+ accepts two Int operands and returns Int.
Auditing callers after an interface change
A warehouse team is reviewing a proposed change to a screening helper. The original interface accepts an integer record number and a Boolean override, returning an integer review code:
The revised interface accepts an integer record number and an integer priority, returning a Boolean approval:
Assume each implementation satisfies its declared interface. Check every expression below independently under each interface, without modifying any expression. Integer literals have type Int, and true and false have type Bool. Addition requires two Int operands and returns Int. Function arguments must match exactly. A conditional requires a Bool condition and branches of the same type; it checks both branches even when its condition is false. There are no implicit conversions or additional value checks.
Reconstructing interfaces across nested calls
A package-scoring program calls two external functions, measure and eligible, whose annotations are missing. Their bodies are unavailable, but each accepts one argument and has one fixed parameter type and one fixed result type throughout the program.
Use these language rules:
The available types are Int, Bool, and String.