File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2158,10 +2158,7 @@ impl Compiler<'_> {
21582158 for ident in attrs. iter ( ) . take ( n_attrs) . skip ( i + 1 ) {
21592159 let other = ident. as_str ( ) ;
21602160 if attr == other {
2161- todo ! ( ) ;
2162- // return Err(self.compiler_error(
2163- // &format!("attribute name repeated in class pattern: {}", attr),
2164- // ));
2161+ return Err ( self . error ( CodegenErrorType :: RepeatedAttributePattern ) ) ;
21652162 }
21662163 }
21672164 }
@@ -2415,15 +2412,16 @@ impl Compiler<'_> {
24152412 } else {
24162413 let control_vec = control. as_ref ( ) . unwrap ( ) ;
24172414 if nstores != control_vec. len ( ) {
2418- todo ! ( ) ;
2419- // return self.compiler_error("alternative patterns bind different names");
2415+ return Err ( self . error ( CodegenErrorType :: ConflictingNameBindPattern ) ) ;
24202416 } else if nstores > 0 {
24212417 // Check that the names occur in the same order.
24222418 for icontrol in ( 0 ..nstores) . rev ( ) {
24232419 let name = & control_vec[ icontrol] ;
24242420 // Find the index of `name` in the current stores.
2425- let istores = pc. stores . iter ( ) . position ( |n| n == name) . unwrap ( ) ;
2426- // .ok_or_else(|| self.compiler_error("alternative patterns bind different names"))?;
2421+ let istores =
2422+ pc. stores . iter ( ) . position ( |n| n == name) . ok_or_else ( || {
2423+ self . error ( CodegenErrorType :: ConflictingNameBindPattern )
2424+ } ) ?;
24272425 if icontrol != istores {
24282426 // The orders differ; we must reorder.
24292427 assert ! ( istores < icontrol, "expected istores < icontrol" ) ;
Original file line number Diff line number Diff line change @@ -65,6 +65,8 @@ pub enum CodegenErrorType {
6565 ForbiddenName ,
6666 DuplicateStore ( String ) ,
6767 UnreachablePattern ( PatternUnreachableReason ) ,
68+ RepeatedAttributePattern ,
69+ ConflictingNameBindPattern ,
6870 NotImplementedYet , // RustPython marker for unimplemented features
6971}
7072
@@ -119,6 +121,12 @@ impl fmt::Display for CodegenErrorType {
119121 UnreachablePattern ( reason) => {
120122 write ! ( f, "{reason} makes remaining patterns unreachable" )
121123 }
124+ RepeatedAttributePattern => {
125+ write ! ( f, "attribute name repeated in class pattern" )
126+ }
127+ ConflictingNameBindPattern => {
128+ write ! ( f, "alternative patterns bind different names" )
129+ }
122130 NotImplementedYet => {
123131 write ! ( f, "RustPython does not implement this feature yet" )
124132 }
You can’t perform that action at this time.
0 commit comments