Fixing bug exposed by functorbug.cpp and factoring out some common functionality between TypeChecker.cpp and EffectConstraintGeneration.cpp