@@ -555,11 +555,12 @@ jl_value_t *jl_parse_eval_all(const char *fname, size_t len)
555
555
{
556
556
//jl_printf(JL_STDERR, "***** loading %s\n", fname);
557
557
int last_lineno = jl_lineno ;
558
+ int top_lineno = -1 ;
558
559
const char * last_filename = jl_filename ;
559
560
jl_lineno = 0 ;
560
561
jl_filename = fname ;
561
- jl_value_t * fn = NULL , * ln = NULL , * form = NULL , * result = jl_nothing ;
562
- JL_GC_PUSH4 (& fn , & ln , & form , & result );
562
+ jl_value_t * fn = NULL , * ln = NULL , * form = NULL , * nest_exc = NULL , * result = jl_nothing ;
563
+ JL_GC_PUSH5 (& fn , & ln , & form , & result , & nest_exc );
563
564
JL_TRY {
564
565
// handle syntax error
565
566
while (1 ) {
@@ -574,22 +575,38 @@ jl_value_t *jl_parse_eval_all(const char *fname, size_t len)
574
575
jl_interpret_toplevel_expr (form );
575
576
}
576
577
}
578
+ top_lineno = jl_lineno ; // jl_parse_next sets lineno.
577
579
result = jl_toplevel_eval_flex (form , 1 );
578
580
}
579
581
}
580
582
JL_CATCH {
581
583
jl_stop_parsing ();
582
- fn = jl_pchar_to_string (fname , len );
583
- ln = jl_box_long (jl_lineno );
584
- jl_lineno = last_lineno ;
585
- jl_filename = last_filename ;
584
+
586
585
if (jl_loaderror_type == NULL ) {
586
+ // reset line and filename before throwing
587
+ jl_lineno = last_lineno ;
588
+ jl_filename = last_filename ;
587
589
jl_rethrow ();
588
590
}
589
- else {
590
- jl_rethrow_other (jl_new_struct (jl_loaderror_type , fn , ln ,
591
- jl_exception_in_transit ));
591
+
592
+ fn = jl_pchar_to_string (jl_filename , strlen (jl_filename ));
593
+ ln = jl_box_long (jl_lineno );
594
+ nest_exc = jl_new_struct (jl_loaderror_type , fn , ln ,
595
+ jl_exception_in_transit );
596
+
597
+ if ((strcmp (jl_filename , fname ) == 0 ) &&
598
+ jl_lineno == top_lineno ) {
599
+ jl_lineno = last_lineno ;
600
+ jl_filename = last_filename ;
601
+ jl_rethrow_other (nest_exc );
592
602
}
603
+
604
+ jl_lineno = last_lineno ;
605
+ jl_filename = last_filename ;
606
+ fn = jl_pchar_to_string (fname , len );
607
+ ln = jl_box_long (top_lineno );
608
+ jl_rethrow_other (jl_new_struct (jl_loaderror_type , fn , ln ,
609
+ nest_exc ));
593
610
}
594
611
jl_stop_parsing ();
595
612
jl_lineno = last_lineno ;
0 commit comments