11use rustpython_codegen:: { compile, symboltable} ;
2- use rustpython_compiler_core:: CodeObject ;
2+ use rustpython_compiler_core:: { BaseError , CodeObject } ;
33use rustpython_parser:: {
44 ast:: { fold:: Fold , ConstantOptimizer , Location } ,
55 error:: ParseErrorType ,
@@ -18,14 +18,21 @@ pub enum CompileErrorType {
1818 Parse ( #[ from] rustpython_parser:: error:: ParseErrorType ) ,
1919}
2020
21+ pub type CompileErrorBody = BaseError < CompileErrorType > ;
22+
2123#[ derive( Debug , thiserror:: Error ) ]
2224pub struct CompileError {
23- pub error : CompileErrorType ,
24- pub source_path : String ,
25- pub location : Location ,
25+ pub body : CompileErrorBody ,
2626 pub statement : Option < String > ,
2727}
2828
29+ impl std:: ops:: Deref for CompileError {
30+ type Target = CompileErrorBody ;
31+ fn deref ( & self ) -> & Self :: Target {
32+ & self . body
33+ }
34+ }
35+
2936impl fmt:: Display for CompileError {
3037 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
3138 let loc = self . location ;
@@ -41,20 +48,18 @@ impl fmt::Display for CompileError {
4148
4249impl CompileError {
4350 fn from_codegen ( error : rustpython_codegen:: error:: CodegenError , source : & str ) -> Self {
51+ let statement = get_statement ( source, error. location ) ;
4452 Self {
45- error : error. error . into ( ) ,
46- location : error. location ,
47- source_path : error. source_path ,
48- statement : get_statement ( source, error. location ) ,
53+ body : error. into ( ) ,
54+ statement,
4955 }
5056 }
5157 fn from_parse ( error : rustpython_parser:: error:: ParseError , source : & str ) -> Self {
52- let error: rustpython_compiler_core:: Error < ParseErrorType > = error. into ( ) ;
58+ let error: rustpython_compiler_core:: BaseError < ParseErrorType > = error. into ( ) ;
59+ let statement = get_statement ( source, error. location ) ;
5360 Self {
54- error : error. error . into ( ) ,
55- location : error. location ,
56- source_path : error. source_path ,
57- statement : get_statement ( source, error. location ) ,
61+ body : error. into ( ) ,
62+ statement,
5863 }
5964 }
6065 fn from_symtable (
0 commit comments