Fix searching declared variables

Use parent's scope when searching declared variables.