diff --git a/docs/docs/language-features.md b/docs/docs/language-features.md index 196be18..474e004 100644 --- a/docs/docs/language-features.md +++ b/docs/docs/language-features.md @@ -167,6 +167,9 @@ class Maths { print(Maths.sum(10, 5)); # Output: 15 ``` +!!! note "Own property access" + Currently, there is no way to access properties from the class from within its own functions (like `self` (python) or `this` (javascript)) + ## Enums Enums can be created using `enum`: diff --git a/eryx/runtime/environment.py b/eryx/runtime/environment.py index dd85922..3503c31 100644 --- a/eryx/runtime/environment.py +++ b/eryx/runtime/environment.py @@ -51,9 +51,8 @@ def declare_variable( ) -> RuntimeValue: """Declare a variable in the current scope.""" # Raise an exception if the variable is already declared - if variable_name in self.variables: - if not overwrite: - raise RuntimeError(f'Variable "{variable_name}" already declared') + if variable_name in self.variables and not overwrite: + raise RuntimeError(f'Variable "{variable_name}" already declared') self.variables[variable_name] = value diff --git a/eryx/runtime/interpreter.py b/eryx/runtime/interpreter.py index 9fcae9e..94d2178 100644 --- a/eryx/runtime/interpreter.py +++ b/eryx/runtime/interpreter.py @@ -98,10 +98,13 @@ def eval_class_declaration( ) if isinstance(method, FunctionDeclaration): + env = Environment( + parent_env=environment, disable_file_io=environment.disable_file_io + ) func = FunctionValue( name=method.name, arguments=method.arguments, - environment=environment, + environment=env, body=method.body, ) class_obj.methods[method.name] = func @@ -468,7 +471,7 @@ def eval_member_expression( member: MemberExpression, environment: Environment ) -> RuntimeValue: """Evaluate a member expression.""" - object_value = evaluate(member.object, environment) + object_value = evaluate(member.object, environment) # if ur reading this, you are silly :3 if isinstance(object_value, (ObjectValue, ClassValue, EnumValue)): if member.computed: