Master the fundamental concepts of semantic analysis through this focused micro-challenge.
C promotes int to float in mixed arithmetic; Java widens primitives automatically. Clang applies standard conversion rules before checking assignment compatibility. Coercion rules are where subtle bugs hide: silent truncation, sign extension, and unexpected overflow.
Integer promotion: char and short widen to int. Usual arithmetic conversions: if one operand is float, the other promotes. Assignment may narrow with a warning or error depending on the language.
cLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will implement type coercion rules for mixed-type arithmetic and assignments. This exercise asks you to promote operand types per language rules and report errors when implicit conversion is not permitted.
Implement type coercion rules for binary operations.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github