regarding type from function:
if it is a new variable the type is needed to declare it, if it is an
already used variable it is enough to know it doesn't change type.
A similar question was asked on StackOverflow about polymorphic functions, and they gave a very simple example of a function that could return multiple types, even non-predictably.
I also found an EETimes article talking about the difficulty in writing a Matlab-to-C translator, and polymorphism came up, among other things, as a particularly challenging translation problem.
I haven't identified any non-custom function that produces highly polymorphic output yet, maybe someone else can think of one. but a simple:
a = 1;
b = 'foo';
[b, a] = deal(a, b)
b = 1
a = foo
could be a problem i guess. this example might be easy to catch, and maybe even correct for, but only if you include 'deal' on a compiler blacklist of functions that can change variable type.