瀏覽代碼

Fixed scope issue of self in functions. Fixes #384.

woollybah 6 年之前
父節點
當前提交
c4644af640
共有 1 個文件被更改,包括 9 次插入2 次删除
  1. 9 2
      expr.bmx

+ 9 - 2
expr.bmx

@@ -24,6 +24,7 @@
 
 Type TExpr
 	Field exprType:TType
+	Field static:Int
 
 	Method ToString$()
 		Return "<TExpr>"
@@ -1142,13 +1143,18 @@ End Type
 Type TSelfExpr Extends TExpr
 
 	Method Copy:TExpr()
-		Return New TSelfExpr
+		Local expr:TExpr = New TSelfExpr
+		expr.static = static
+		Return expr
 	End Method
 
 	Method Semant:TExpr()
 		If exprType Return Self
 
-		'If _env.FuncScope().IsStatic() Err "Illegal use of Self within static scope."
+		If _env.FuncScope().IsStatic() Then
+			static = True
+		End If
+		
 		Local scope:TClassDecl = _env.ClassScope()
 		If Not scope Then
 			Err "'Self' can only be used within methods."
@@ -2543,6 +2549,7 @@ Type TIdentExpr Extends TExpr
 				static=True
 			Else
 				expr=expr.Semant()
+				static = expr.static
 				scope=expr.exprType.GetClass()
 				If Not scope Then
 					Err "Expression has no scope"