IUCompilerCourse / Essentials-of-Compilation

A book about compiling Racket and Python to x86-64 assembly
1.27k stars 137 forks source link

Ch. 8 Python: Behavior of functions that return nothing or "fall off the end" is not described. #144

Closed AndrewTolmach closed 1 year ago

AndrewTolmach commented 1 year ago

Ch. 8 doesn't say what happens if a function "falls off the end" and, more generally, doesn't indicate whether it is possible to write return None or just return. Experimenting with the implementation suggests that return None is intended to be valid, and that falling off the end has the same effect, but bare return is not allowed. (The implementation was not entirely working, however -- see related PRs). In any case, the book should say just a few words about this.

jsiek commented 1 year ago

Thanks!

It looks like the type checking code in the book got out-of-date. I've updated type_check_stmts to return VoidType when ss is empty. Also, the text was completely missing a description of how to type check function definitions. I've added a description.