Browse Source

Resolved unary expression with Var issue. Fixes #47.

woollybah 11 years ago
parent
commit
c4b13c1b0d
2 changed files with 24 additions and 1 deletions
  1. 8 1
      expr.bmx
  2. 16 0
      tests/framework/language/var_03.bmx

+ 8 - 1
expr.bmx

@@ -1129,8 +1129,15 @@ Type TUnaryExpr Extends TExpr
 		Select op
 		Case "+","-"
 			expr=expr.Semant()
-			If Not TNumericType( expr.exprType ) Err expr.ToString()+" must be numeric for use with unary operator '"+op+"'"
+			If Not TNumericType( expr.exprType ) Or IsPointerType(expr.exprType) Then
+				Err expr.ToString()+" must be numeric for use with unary operator '"+op+"'"
+			End If
 			exprType=expr.exprType
+			' Remove Var-ness, if required. "expr" will still be "Var"
+			If exprType._flags & TType.T_VAR Then
+				exprType = exprType.Copy()
+				exprType._flags :~ TType.T_VAR
+			End If
 		Case "~~"
 			expr=expr.SemantAndCast( New TIntType )
 			exprType=New TIntType

+ 16 - 0
tests/framework/language/var_03.bmx

@@ -0,0 +1,16 @@
+SuperStrict
+
+Framework brl.standardio
+
+Type testtype
+    Field f:Float
+
+    Function test(f:Float Var)
+        'fails
+        f = -f*0.5
+        'would work
+        'f = -1 * f*0.5
+    End Function
+EndType
+
+