top down typechecker and tests for it