@@ -395,6 +395,10 @@ pub const ErrorDetails = struct {
395395 // General (used in various places)
396396 /// `number` is populated and contains the value that the ordinal would have in the Win32 RC compiler implementation
397397 win32_non_ascii_ordinal ,
398+
399+ // Initialization
400+ /// `file_open_error` is populated, but `filename_string_index` is not
401+ failed_to_open_cwd ,
398402 };
399403
400404 pub fn render (self : ErrorDetails , writer : anytype , source : []const u8 , strings : []const []const u8 ) ! void {
@@ -766,6 +770,9 @@ pub const ErrorDetails = struct {
766770 .note = > return writer .print ("the Win32 RC compiler would accept this as an ordinal but its value would be {}" , .{self .extra .number }),
767771 .hint = > return ,
768772 },
773+ .failed_to_open_cwd = > {
774+ try writer .print ("failed to open CWD for compilation: {s}" , .{@tagName (self .extra .file_open_error .err )});
775+ },
769776 }
770777 }
771778
@@ -804,7 +811,8 @@ pub const ErrorDetails = struct {
804811 .point_offset = self .token .start - source_line_start ,
805812 .after_len = after : {
806813 const end = @min (source_line_end , if (self .token_span_end ) | span_end | span_end .end else self .token .end );
807- if (end == self .token .start ) break :after 0 ;
814+ // end may be less than start when pointing to EOF
815+ if (end <= self .token .start ) break :after 0 ;
808816 break :after end - self .token .start - 1 ;
809817 },
810818 },
@@ -816,13 +824,18 @@ pub fn renderErrorMessage(allocator: std.mem.Allocator, writer: anytype, tty_con
816824 if (err_details .type == .hint ) return ;
817825
818826 const source_line_start = err_details .token .getLineStart (source );
819- const column = err_details .token .calculateColumn (source , 1 , source_line_start );
820-
821- // var counting_writer_container = std.io.countingWriter(writer);
822- // const counting_writer = counting_writer_container.writer();
823-
824- const corresponding_span : ? SourceMappings.SourceSpan = if (source_mappings ) | mappings | mappings .get (err_details .token .line_number ) else null ;
825- const corresponding_file : ? []const u8 = if (source_mappings ) | mappings | mappings .files .get (corresponding_span .? .filename_offset ) else null ;
827+ // Treat tab stops as 1 column wide for error display purposes,
828+ // and add one to get a 1-based column
829+ const column = err_details .token .calculateColumn (source , 1 , source_line_start ) + 1 ;
830+
831+ const corresponding_span : ? SourceMappings.SourceSpan = if (source_mappings != null and source_mappings .? .has (err_details .token .line_number ))
832+ source_mappings .? .get (err_details .token .line_number )
833+ else
834+ null ;
835+ const corresponding_file : ? []const u8 = if (source_mappings != null and corresponding_span != null )
836+ source_mappings .? .files .get (corresponding_span .? .filename_offset )
837+ else
838+ null ;
826839
827840 const err_line = if (corresponding_span ) | span | span .start_line else err_details .token .line_number ;
828841
@@ -897,7 +910,7 @@ pub fn renderErrorMessage(allocator: std.mem.Allocator, writer: anytype, tty_con
897910 try writer .writeByte ('\n ' );
898911 try tty_config .setColor (writer , .reset );
899912
900- if (source_mappings ) | _ | {
913+ if (corresponding_span != null and corresponding_file != null ) {
901914 var corresponding_lines = try CorrespondingLines .init (allocator , cwd , err_details , source_line_for_display_buf .items , corresponding_span .? , corresponding_file .? );
902915 defer corresponding_lines .deinit (allocator );
903916
0 commit comments