Backport of semantic type support from 0.6

recreating same pull request targeting 0.4.2