Index: src/ResolvExpr/CandidateFinder.cpp
===================================================================
--- src/ResolvExpr/CandidateFinder.cpp	(revision 689d0575efebba7e0ece164aab8e2967a9548a43)
+++ src/ResolvExpr/CandidateFinder.cpp	(revision 857b5f94b11520c80efa84eab7d4104469b9e9da)
@@ -672,4 +672,5 @@
 		void postvisit( const ast::SizeofExpr * sizeofExpr );
 		void postvisit( const ast::AlignofExpr * alignofExpr );
+		void postvisit( const ast::CountofExpr * countExpr );
 		void postvisit( const ast::AddressExpr * addressExpr );
 		void postvisit( const ast::LabelAddressExpr * labelExpr );
@@ -697,5 +698,4 @@
 		void postvisit( const ast::UntypedInitExpr * initExpr );
 		void postvisit( const ast::QualifiedNameExpr * qualifiedExpr );
-		void postvisit( const ast::CountExpr * countExpr );
 
 		void postvisit( const ast::InitExpr * ) {
@@ -941,5 +941,4 @@
 		}
 	}
-	
 
 	/// Adds aggregate member interpretations
@@ -1269,5 +1268,5 @@
 					? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env )
 					: castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env );
-			
+
 			// Redefine enum cast
 			auto argAsEnum = fromType.as<ast::EnumInstType>();
@@ -1493,20 +1492,13 @@
 	}
 
-	void Finder::postvisit( const ast::CountExpr * countExpr ) {
-		const ast::UntypedExpr * untyped = nullptr;
-		if ( countExpr->type ) {
-			auto enumInst = countExpr->type.as<ast::EnumInstType>();
-			if ( enumInst ) {
-				addCandidate( ast::ConstantExpr::from_ulong(countExpr->location, enumInst->base->members.size()), tenv );
-				return;
-			}
-			auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} );
-			auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type );
-			untyped = ast::UntypedExpr::createCall(
-				countExpr->location, "Countof", { castFirst }
-			);
-		}
-		if (!untyped) untyped = ast::UntypedExpr::createCall(
-				countExpr->location, "Countof", { countExpr->expr }
+	void Finder::postvisit( const ast::CountofExpr * countExpr ) {
+		if ( auto enumInst = countExpr->type.as<ast::EnumInstType>() ) {
+			addCandidate( ast::ConstantExpr::from_ulong( countExpr->location, enumInst->base->members.size()), tenv );
+			return;
+		}
+		auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} );
+		auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type );
+		const ast::UntypedExpr * untyped = ast::UntypedExpr::createCall(
+			countExpr->location, "Countof", { castFirst }
 		);
 		CandidateFinder finder( context, tenv );
@@ -1514,8 +1506,8 @@
 		CandidateList winners = findMinCost( finder.candidates );
 		if ( winners.size() == 0 ) {
-			SemanticError( countExpr->expr, "Countof is not implemented for operand: " );
-		}
-		if ( winners.size() !=  1 ) {
-			SemanticError( countExpr->expr, "Ambiguous expression in countof operand: " );
+			SemanticError( countExpr, "Countof is not implemented: " );
+		}
+		if ( winners.size() != 1 ) {
+			SemanticError( countExpr, "Ambiguous expression in countof: " );
 		}
 		CandidateRef & choice = winners.front();
