@@ -854,23 +854,13 @@ public Object visitDecorated(Python3Parser.DecoratedContext ctx) {
854
854
ExpressionNode definition ;
855
855
String definitionName ;
856
856
if (ctx .classdef () != null ) {
857
- definition = ( ExpressionNode ) ctx .classdef ().accept (this );
857
+ definition = asDefinition ( ctx .classdef ().accept (this ) );
858
858
definitionName = ctx .classdef ().NAME ().getText ();
859
859
} else if (ctx .funcdef () != null ) {
860
- Object accept = ctx .funcdef ().accept (this );
861
- if (accept instanceof WriteNode ) {
862
- definition = ((WriteNode ) accept ).getRhs ();
863
- } else {
864
- definition = (ExpressionNode ) accept ;
865
- }
860
+ definition = asDefinition (ctx .funcdef ().accept (this ));
866
861
definitionName = ctx .funcdef ().NAME ().getText ();
867
862
} else if (ctx .async_funcdef () != null ) {
868
- Object accept = ctx .async_funcdef ().accept (this );
869
- if (accept instanceof WriteNode ) {
870
- definition = ((WriteNode ) accept ).getRhs ();
871
- } else {
872
- definition = (ExpressionNode ) accept ;
873
- }
863
+ definition = asDefinition (ctx .async_funcdef ().accept (this ));
874
864
definitionName = ctx .async_funcdef ().funcdef ().NAME ().getText ();
875
865
} else {
876
866
throw new RuntimeException ("unsupported decorated definition" );
@@ -882,6 +872,18 @@ public Object visitDecorated(Python3Parser.DecoratedContext ctx) {
882
872
return environment .findVariable (definitionName ).makeWriteNode (definition );
883
873
}
884
874
875
+ private static ExpressionNode asDefinition (Object accept ) {
876
+ ExpressionNode definition ;
877
+ if (accept instanceof WriteNode ) {
878
+ definition = ((WriteNode ) accept ).getRhs ();
879
+ } else if (accept instanceof ExpressionNode ) {
880
+ definition = (ExpressionNode ) accept ;
881
+ } else {
882
+ throw new IllegalArgumentException ();
883
+ }
884
+ return definition ;
885
+ }
886
+
885
887
private ExpressionNode getRhsImport (Python3Parser .Dotted_nameContext ctx , ExpressionNode importNode ) {
886
888
ExpressionNode rhsImport = importNode ;
887
889
for (int i = 1 ;; i ++) {
@@ -1707,8 +1709,13 @@ public Object visitClassdef(Python3Parser.ClassdefContext ctx) {
1707
1709
ExpressionNode owner = factory .createGetAttribute (factory .createBuiltinsLiteral (), __BUILD_CLASS__ );
1708
1710
ExpressionNode classDef = PythonCallNode .create (owner , argumentNodes .toArray (new ExpressionNode [0 ]), keywords .toArray (new ExpressionNode [0 ]), splatArguments [0 ], splatArguments [1 ]);
1709
1711
deriveSourceSection (ctx , classDef );
1712
+
1710
1713
ReadNode read = environment .findVariable (className );
1711
- return factory .createBlock (read .makeWriteNode (classDef ), factory .createWriteCellVar ((ExpressionNode ) read , classBodyRoot , __CLASS__ ));
1714
+
1715
+ ReadNode tempLocal = environment .makeTempLocalVariable ();
1716
+ ExpressionNode newClass = ((ExpressionNode ) tempLocal ).withSideEffect (
1717
+ factory .createBlock (tempLocal .makeWriteNode (classDef ), factory .createWriteCellVar ((ExpressionNode ) tempLocal , classBodyRoot , __CLASS__ )));
1718
+ return read .makeWriteNode (newClass );
1712
1719
}
1713
1720
1714
1721
@ SuppressWarnings ("unchecked" )
0 commit comments