Browse Source

Fixed 'For var=...' with non-local var bug.

Mark Sibly 9 years ago
parent
commit
c1945a2ab8
3 changed files with 7 additions and 19 deletions
  1. 3 3
      src/mx2new/func.monkey2
  2. 3 14
      src/mx2new/scope.monkey2
  3. 1 2
      src/mx2new/stmtexpr.monkey2

+ 3 - 3
src/mx2new/func.monkey2

@@ -372,12 +372,12 @@ Class FuncValue Extends Value
 		
 		If Not fdecl.IsAbstract
 			
-			Local reachable:=block.Semant( fdecl.stmts )
+			block.Semant( fdecl.stmts )
 			
-			If reachable And ftype.retType<>Type.VoidType Throw New SemantEx( "Missing return statement" )
+			If block.reachable And ftype.retType<>Type.VoidType Throw New SemantEx( "Missing return statement" )
 
 			SemantInvokeNew()
-			
+
 		Endif
 		
 		If fdecl.kind="function" Or IsExtension

+ 3 - 14
src/mx2new/scope.monkey2

@@ -331,7 +331,7 @@ Class Block Extends Scope
 
 	Field stmts:=New Stack<Stmt>
 	
-	Field reachable:Bool
+	Field reachable:Bool=True
 	
 	Field loop:Bool
 	Field inex:Bool
@@ -389,28 +389,17 @@ Class Block Extends Scope
 		If reachable stmts.Push( stmt )
 	End
 	
-	Method Semant:Bool( stmts:StmtExpr[] )
+	Method Semant( stmts:StmtExpr[] )
 	
-		reachable=True
-
 		For Local expr:=Eachin stmts
-		
 			Try
-			
+
 				Local stmt:=expr.Semant( Self )
-				
 				If stmt Emit( stmt )
 				
 			Catch ex:SemantEx
 			End
-
 		Next
-		
-		Local result:=reachable
-		
-		reachable=True
-		
-		Return result
 	End
 	
 	Method AllocLocal:VarValue( init:Value )

+ 1 - 2
src/mx2new/stmtexpr.monkey2

@@ -255,12 +255,11 @@ Class ReturnStmtExpr Extends StmtExpr
 			Endif
 			
 			block.Emit( New ReturnStmt( Self,value ) )
+			block.reachable=False
 		
 		Catch ex:SemantEx
 		End
 		
-		block.reachable=False
-		
 		Return Null
 	End