Index: src/CodeGen/CodeGenerator.cc
===================================================================
--- src/CodeGen/CodeGenerator.cc	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/CodeGen/CodeGenerator.cc	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -262,5 +262,8 @@
 			} // if
 		} else {
-			output << typeDecl->typeString() << " " << typeDecl->get_name();
+			output << typeDecl->genTypeString() << " " << typeDecl->get_name();
+			if ( typeDecl->get_kind() != TypeDecl::Any && typeDecl->get_sized() ) {
+				output << " | sized(" << typeDecl->get_name() << ")";
+			}
 			if ( ! typeDecl->get_assertions().empty() ) {
 				output << " | { ";
@@ -769,6 +772,9 @@
 	void CodeGenerator::visit( ExprStmt * exprStmt ) {
 		assert( exprStmt );
-		// cast the top-level expression to void to reduce gcc warnings.
-		Expression * expr = new CastExpr( exprStmt->get_expr() );
+		Expression * expr = exprStmt->get_expr();
+		if ( genC ) {
+			// cast the top-level expression to void to reduce gcc warnings.
+			expr = new CastExpr( expr );
+		}
 		expr->accept( *this );
 		output << ";";
Index: src/CodeGen/Generate.cc
===================================================================
--- src/CodeGen/Generate.cc	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/CodeGen/Generate.cc	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -22,5 +22,9 @@
 #include "SynTree/Declaration.h"
 #include "CodeGenerator.h"
-#include "Tuples/Tuples.h"
+#include "GenType.h"
+#include "SynTree/SynTree.h"
+#include "SynTree/Type.h"
+#include "SynTree/BaseSyntaxNode.h"
+// #include "Tuples/Tuples.h"
 
 using namespace std;
@@ -39,4 +43,14 @@
 		} // for
 	}
+
+	void generate( BaseSyntaxNode * node, std::ostream & os ) {
+		if ( Type * type = dynamic_cast< Type * >( node ) ) {
+			os << CodeGen::genPrettyType( type, "" );
+		} else {
+			CodeGen::CodeGenerator cgv( os, true, false );
+			node->accept( cgv );
+		}
+		os << std::endl;
+	}
 } // namespace CodeGen
 
Index: src/CodeGen/Generate.h
===================================================================
--- src/CodeGen/Generate.h	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/CodeGen/Generate.h	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -25,4 +25,7 @@
 	/// Generates code. doIntrinsics determines if intrinsic functions are printed, pretty formats output nicely (e.g., uses unmangled names, etc.), generateC is true when the output must consist only of C code (allows some assertions, etc.)
 	void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false );
+
+	/// Generate code for a single node -- helpful for debugging in gdb
+	void generate( BaseSyntaxNode * node, std::ostream & os );
 } // namespace CodeGen
 
Index: src/GenPoly/PolyMutator.cc
===================================================================
--- src/GenPoly/PolyMutator.cc	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/GenPoly/PolyMutator.cc	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -50,4 +50,11 @@
 
 	Statement * PolyMutator::mutateStatement( Statement *stmt ) {
+		// don't want statements from outer CompoundStmts to be added to this CompoundStmt
+		ValueGuard< std::list< Statement* > > oldStmtsToAdd( stmtsToAdd );
+		ValueGuard< std::list< Statement* > > oldStmtsToAddAfter( stmtsToAddAfter );
+		ValueGuard< TypeSubstitution * > oldEnv( env );
+		stmtsToAdd.clear();
+		stmtsToAddAfter.clear();
+
 		Statement *newStmt = maybeMutate( stmt, *this );
 		if ( ! stmtsToAdd.empty() || ! stmtsToAddAfter.empty() ) {
@@ -83,33 +90,33 @@
 
 	Statement * PolyMutator::mutate(IfStmt *ifStmt) {
+		ifStmt->set_condition(  mutateExpression( ifStmt->get_condition() ) );
 		ifStmt->set_thenPart(  mutateStatement( ifStmt->get_thenPart() ) );
 		ifStmt->set_elsePart(  mutateStatement( ifStmt->get_elsePart() ) );
-		ifStmt->set_condition(  mutateExpression( ifStmt->get_condition() ) );
 		return ifStmt;
 	}
 
 	Statement * PolyMutator::mutate(WhileStmt *whileStmt) {
+		whileStmt->set_condition(  mutateExpression( whileStmt->get_condition() ) );
 		whileStmt->set_body(  mutateStatement( whileStmt->get_body() ) );
-		whileStmt->set_condition(  mutateExpression( whileStmt->get_condition() ) );
 		return whileStmt;
 	}
 
 	Statement * PolyMutator::mutate(ForStmt *forStmt) {
-		forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
 		mutateAll( forStmt->get_initialization(), *this );
 		forStmt->set_condition(  mutateExpression( forStmt->get_condition() ) );
 		forStmt->set_increment(  mutateExpression( forStmt->get_increment() ) );
+		forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
 		return forStmt;
 	}
 
 	Statement * PolyMutator::mutate(SwitchStmt *switchStmt) {
+		switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
 		mutateStatementList( switchStmt->get_statements() );
-		switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
 		return switchStmt;
 	}
 
 	Statement * PolyMutator::mutate(CaseStmt *caseStmt) {
+		caseStmt->set_condition(  mutateExpression( caseStmt->get_condition() ) );
 		mutateStatementList( caseStmt->get_statements() );
-		caseStmt->set_condition(  mutateExpression( caseStmt->get_condition() ) );
 		return caseStmt;
 	}
Index: src/ResolvExpr/AlternativeFinder.cc
===================================================================
--- src/ResolvExpr/AlternativeFinder.cc	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/ResolvExpr/AlternativeFinder.cc	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -766,13 +766,16 @@
 			} // if
 		} // for
-		// function may return struct or union value, in which case we need to add alternatives for implicit conversions to each of the anonymous members
+
+		candidates.clear();
+		candidates.splice( candidates.end(), alternatives );
+
+		findMinCost( candidates.begin(), candidates.end(), std::back_inserter( alternatives ) );
+
+		// function may return struct or union value, in which case we need to add alternatives for implicit
+		// conversions to each of the anonymous members, must happen after findMinCost since anon conversions
+		// are never the cheapest expression
 		for ( const Alternative & alt : alternatives ) {
 			addAnonConversions( alt );
 		}
-
-		candidates.clear();
-		candidates.splice( candidates.end(), alternatives );
-
-		findMinCost( candidates.begin(), candidates.end(), std::back_inserter( alternatives ) );
 
 		if ( alternatives.empty() && targetType && ! targetType->isVoid() ) {
Index: src/SynTree/BaseSyntaxNode.h
===================================================================
--- src/SynTree/BaseSyntaxNode.h	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/SynTree/BaseSyntaxNode.h	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -18,8 +18,11 @@
 
 #include "Common/utility.h"
+#include "Visitor.h"
 
 class BaseSyntaxNode {
   public:
 	CodeLocation location;
+
+	virtual void accept( Visitor & v ) = 0; // temporary -- needs to be here so that BaseSyntaxNode is polymorphic and can be dynamic_cast
 };
 
Index: src/SynTree/Declaration.h
===================================================================
--- src/SynTree/Declaration.h	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/SynTree/Declaration.h	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -204,4 +204,5 @@
 
 	virtual std::string typeString() const;
+	virtual std::string genTypeString() const;
 
 	virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
Index: src/SynTree/SynTree.h
===================================================================
--- src/SynTree/SynTree.h	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/SynTree/SynTree.h	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -21,4 +21,6 @@
 #include <map>
 #include <iostream>
+
+class BaseSyntaxNode;
 
 class Declaration;
Index: src/SynTree/TypeDecl.cc
===================================================================
--- src/SynTree/TypeDecl.cc	(revision 43426d4727f68ab5efacae23b05f3882ea0c5bf4)
+++ src/SynTree/TypeDecl.cc	(revision 982ed5bff06f40e924f08895f049b94b54876da1)
@@ -29,4 +29,9 @@
 }
 
+std::string TypeDecl::genTypeString() const {
+	static const std::string kindNames[] = { "otype", "dtype", "ftype", "ttype" };
+	return kindNames[ kind ];
+}
+
 std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) {
   return os << data.kind << ", " << data.isComplete;
