Skip to content

Commit

Permalink
type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SpGerg committed Jan 20, 2024
1 parent 60e3f88 commit dc03302
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Binary file modified Imports/PaganismCustomConsole/Paganism.dll
Binary file not shown.
15 changes: 15 additions & 0 deletions Paganism/Interpreter/Data/DataStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ public bool IsLanguage(string name)
return Language.ContainsKey(name);
}

public bool TryGet(BlockStatementExpression expression, string name, out T value)
{
try
{
value = Get(expression, name);

return true;
}
catch
{
value = default;
return false;
}
}

public T Get(BlockStatementExpression expression, string name)
{
if (Language.ContainsKey(name))
Expand Down
17 changes: 10 additions & 7 deletions Paganism/PParser/AST/BinaryOperatorExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,21 +310,24 @@ public Value Assign()

if (Left is VariableExpression variableExpression)
{
if (variableExpression.Type is null)
if (!Variables.Instance.Value.TryGet(Parent, variableExpression.Name, out var result))
{
variableExpression = new VariableExpression(variableExpression.Parent, variableExpression.Line, variableExpression.Position, variableExpression.Filepath,
variableExpression.Name, new TypeValue(value.Type, value is TypeValue typeValue ? typeValue.StructureName : string.Empty));
if (variableExpression.Type is null)
{
variableExpression = new VariableExpression(variableExpression.Parent, variableExpression.Line, variableExpression.Position, variableExpression.Filepath,
variableExpression.Name, new TypeValue(value.Type, value is TypeValue typeValue ? typeValue.StructureName : string.Empty));
}
}
else
{
if (value.Type != variableExpression.Type.Value)
if (value.Type != result.Type)
{
throw new InterpreterException($"Except {variableExpression.Type.Value} type", variableExpression.Line, variableExpression.Position);
throw new InterpreterException($"Except {result.Type} type", variableExpression.Line, variableExpression.Position);
}

if (variableExpression.Type.Value is TypesType.Structure && value is StructureValue structureValue && variableExpression.Type.StructureName != structureValue.Structure.Name)
if (result is StructureValue structureValue1 && value is StructureValue structureValue && structureValue1.Structure.Name != structureValue.Structure.Name)
{
throw new InterpreterException($"Except {variableExpression.Type.StructureName} structure type", variableExpression.Line, variableExpression.Position);
throw new InterpreterException($"Except {structureValue1.Structure.Name} structure type", variableExpression.Line, variableExpression.Position);
}
}

Expand Down

0 comments on commit dc03302

Please sign in to comment.