Index: src/Common/utility.h
===================================================================
--- src/Common/utility.h	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
+++ src/Common/utility.h	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
@@ -322,5 +322,5 @@
 	std::string filename;
 
-    /// Create a new unset CodeLocation.
+	/// Create a new unset CodeLocation.
 	CodeLocation()
 		: linenumber( -1 )
@@ -328,5 +328,5 @@
 	{}
 
-    /// Create a new CodeLocation with the given values.
+	/// Create a new CodeLocation with the given values.
 	CodeLocation( const char* filename, int lineno )
 		: linenumber( lineno )
@@ -334,11 +334,11 @@
 	{}
 
-    bool isSet () const {
-        return -1 != linenumber;
-    }
-
-    bool isUnset () const {
-        return !isSet();
-    }
+	bool isSet () const {
+		return -1 != linenumber;
+	}
+
+	bool isUnset () const {
+		return !isSet();
+	}
 
 	void unset () {
@@ -353,4 +353,5 @@
 	return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + " " : "";
 }
+
 #endif // _UTILITY_H
 
Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
+++ src/GenPoly/Box.cc	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
@@ -765,4 +765,8 @@
 						arg = new AddressExpr( arg );
 					}
+					if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) {
+						// silence warnings by casting boxed parameters when the actual type does not match up with the formal type.
+						arg = new CastExpr( arg, param->clone() );
+					}
 				} else {
 					// use type computed in unification to declare boxed variables
@@ -902,6 +906,5 @@
 				} // if
 				UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
-				UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
-				deref->get_args().push_back( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType->get_returnVals().front()->get_type()->clone() ) ) );
+				UntypedExpr *deref = UntypedExpr::createDeref( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType->get_returnVals().front()->get_type()->clone() ) ) );
 				assign->get_args().push_back( deref );
 				addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
@@ -1217,11 +1220,4 @@
 
 		Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
-			// maybe need access to the env when mutating the expr
-			if ( Expression * expr = returnStmt->get_expr() ) {
-				if ( expr->get_env() ) {
-					env = expr->get_env();
-				}
-			}
-
 			if ( retval && returnStmt->get_expr() ) {
 				assert( returnStmt->get_expr()->has_result() && ! returnStmt->get_expr()->get_result()->isVoid() );
@@ -1539,6 +1535,6 @@
 					Type *declType = objectDecl->get_type();
 					std::string bufName = bufNamer.newName();
-					ObjectDecl *newBuf = new ObjectDecl( bufName, Type::StorageClasses(), LinkageSpec::C, 0, 
-						new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ), 
+					ObjectDecl *newBuf = new ObjectDecl( bufName, Type::StorageClasses(), LinkageSpec::C, 0,
+						new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ),
 						true, false, std::list<Attribute*>{ new Attribute( std::string{"aligned"}, std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ) } ), 0 );
 					stmtsToAdd.push_back( new DeclStmt( noLabels, newBuf ) );
@@ -1578,15 +1574,4 @@
 		}
 
-		/// Returns an expression dereferenced n times
-		Expression *makeDerefdVar( Expression *derefdVar, long n ) {
-			for ( int i = 1; i < n; ++i ) {
-				UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
-				derefExpr->get_args().push_back( derefdVar );
-				// xxx - should set results on derefExpr
-				derefdVar = derefExpr;
-			}
-			return derefdVar;
-		}
-
 		Expression *PolyGenericCalculator::mutate( MemberExpr *memberExpr ) {
 			// mutate, exiting early if no longer MemberExpr
@@ -1595,14 +1580,7 @@
 			if ( ! memberExpr ) return expr;
 
-			// get declaration for base struct, exiting early if not found
-			int varDepth;
-			VariableExpr *varExpr = getBaseVar( memberExpr->get_aggregate(), &varDepth );
-			if ( ! varExpr ) return memberExpr;
-			ObjectDecl *objectDecl = dynamic_cast< ObjectDecl* >( varExpr->get_var() );
-			if ( ! objectDecl ) return memberExpr;
-
 			// only mutate member expressions for polymorphic types
 			int tyDepth;
-			Type *objectType = hasPolyBase( objectDecl->get_type(), scopeTyVars, &tyDepth );
+			Type *objectType = hasPolyBase( memberExpr->get_aggregate()->get_result(), scopeTyVars, &tyDepth );
 			if ( ! objectType ) return memberExpr;
 			findGeneric( objectType ); // ensure layout for this type is available
@@ -1622,8 +1600,13 @@
 				fieldLoc->get_args().push_back( aggr );
 				fieldLoc->get_args().push_back( makeOffsetIndex( objectType, i ) );
+				fieldLoc->set_result( memberExpr->get_result()->clone() );
 				newMemberExpr = fieldLoc;
 			} else if ( dynamic_cast< UnionInstType* >( objectType ) ) {
-				// union members are all at offset zero, so build appropriately-dereferenced variable
-				newMemberExpr = makeDerefdVar( varExpr->clone(), varDepth );
+				// union members are all at offset zero, so just use the aggregate expr
+				Expression * aggr = memberExpr->get_aggregate()->clone();
+				delete aggr->get_env(); // xxx - there's a problem with keeping the env for some reason, so for now just get rid of it
+				aggr->set_env( nullptr );
+				newMemberExpr = aggr;
+				newMemberExpr->set_result( memberExpr->get_result()->clone() );
 			} else return memberExpr;
 			assert( newMemberExpr );
@@ -1633,6 +1616,5 @@
 				// Not all members of a polymorphic type are themselves of polymorphic type; in this case the member expression should be wrapped and dereferenced to form an lvalue
 				CastExpr *ptrCastExpr = new CastExpr( newMemberExpr, new PointerType( Type::Qualifiers(), memberType->clone() ) );
-				UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
-				derefExpr->get_args().push_back( ptrCastExpr );
+				UntypedExpr *derefExpr = UntypedExpr::createDeref( ptrCastExpr );
 				newMemberExpr = derefExpr;
 			}
Index: src/tests/.expect/genericUnion.txt
===================================================================
--- src/tests/.expect/genericUnion.txt	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
+++ src/tests/.expect/genericUnion.txt	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
@@ -0,0 +1,2 @@
+00000000 ffffffff
+00000000 ffffffff
Index: src/tests/Makefile.am
===================================================================
--- src/tests/Makefile.am	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
+++ src/tests/Makefile.am	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
@@ -17,5 +17,5 @@
 debug=yes
 
-quick_test=vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once
+quick_test=vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once attributes
 
 if BUILD_CONCURRENCY
@@ -30,5 +30,5 @@
 # applies to both programs
 EXTRA_FLAGS =
-BUILD_FLAGS = -g -Wall -Wno-unused-function @CFA_FLAGS@ ${EXTRA_FLAGS}
+BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ ${EXTRA_FLAGS}
 TEST_FLAGS = $(if $(test), 2> .err/${@}.log, )
 CFLAGS = ${TEST_FLAGS} ${BUILD_FLAGS}
Index: src/tests/Makefile.in
===================================================================
--- src/tests/Makefile.in	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
+++ src/tests/Makefile.in	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
@@ -226,5 +226,5 @@
 quick_test = vector_test avl_test operators numericConstants \
 	expression enum array typeof cast dtor-early-exit init_once \
-	$(am__append_1)
+	attributes $(am__append_1)
 @BUILD_CONCURRENCY_FALSE@concurrent = no
 @BUILD_CONCURRENCY_TRUE@concurrent = yes
@@ -234,5 +234,5 @@
 # applies to both programs
 EXTRA_FLAGS = 
-BUILD_FLAGS = -g -Wall -Wno-unused-function @CFA_FLAGS@ ${EXTRA_FLAGS}
+BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ ${EXTRA_FLAGS}
 TEST_FLAGS = $(if $(test), 2> .err/${@}.log, )
 fstream_test_SOURCES = fstream_test.c
Index: src/tests/genericUnion.c
===================================================================
--- src/tests/genericUnion.c	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
+++ src/tests/genericUnion.c	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
@@ -0,0 +1,30 @@
+#include <limits>
+
+forall(otype T)
+union ByteView {
+	T val;
+	char bytes[(sizeof(int))]; // want to change to sizeof(T)
+};
+
+forall(otype T)
+void print(ByteView(T) x) {
+	for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T)
+		printf("%02x", x.bytes[i] & 0xff);
+	}
+}
+
+forall(otype T)
+void f(ByteView(T) x, T val) {
+	print(x);
+	printf(" ");
+	x.val = val;
+	print(x);
+	printf("\n");
+}
+
+int main() {
+	ByteView(unsigned) u = { 0 };
+	ByteView(int) i = { 0 };
+	f(u, MAX);
+	f(i, -1);
+}
Index: src/tests/test.py
===================================================================
--- src/tests/test.py	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
+++ src/tests/test.py	(revision ad1770be8bf86f42ffbb26be74b2ba25f109bce8)
@@ -28,5 +28,5 @@
 	sh('echo "void ?{}(int*a,int b){}int main(){return 0;}" > .dummy.c')
 	ret, out = sh("make .dummy -s", print2stdout=True)
-	
+
 	if ret != 0:
 		print("Failed to identify architecture:")
@@ -161,5 +161,5 @@
 
 	# build, skipping to next test on error
-	make_ret, _ = sh("""%s test=yes EXTRA_FLAGS="-quiet %s" %s 2> %s 1> /dev/null""" % (make_cmd, options, test.name, out_file), dry_run)
+	make_ret, _ = sh("""%s test=yes EXTRA_FLAGS="%s" %s 2> %s 1> /dev/null""" % (make_cmd, options, test.name, out_file), dry_run)
 
 	# if the make command succeds continue otherwise skip to diff
@@ -192,5 +192,5 @@
 		# fetch return code and error from the diff command
 		retcode, error = diff(".expect/%s.txt" % test.path, ".out/%s.log" % test.name, dry_run)
-	
+
 	# clean the executable
 	sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run)
@@ -269,6 +269,6 @@
 if __name__ == "__main__":
 	#always run from same folder
-	chdir() 
-	
+	chdir()
+
 	# parse the command line arguments
 	options = getOptions()
