diff --git a/compiler2/CompilerError.cc b/compiler2/CompilerError.cc
index 3f07868b773c9635ce18c7e60467ea556b160583..da40be4ea37546956ecb7b48e15568c0fc4f0883 100644
--- a/compiler2/CompilerError.cc
+++ b/compiler2/CompilerError.cc
@@ -265,9 +265,10 @@ namespace Common {
       // borrow location information from the innermost context
       Location my_location;
       my_location.set_location( *(tail->location) );
-      loc = &my_location;
+      my_location.print_location(stderr);
+    } else if (loc) {
+      loc->print_location(stderr);
     }
-    if (loc) loc->print_location(stderr);
     fputs("error: ", stderr);
     vfprintf(stderr, fmt, args);
     putc('\n', stderr);